C # multiple sources, different threads, one event handler

I need someone with high skills in streaming and event assembly.

I have an abstract class A, and two specific classes C1, C2(for example, plug-ins).

Since I need them to communicate with each other as a “plug-in application”, “plug-in-plug-in”, I have a method ExecuteCommandin an abstract class that should do this. This function calls the application eventto process a specific command and returns the result (for example, if one plugin needs data from the application, which it calls ExecuteCommandfrom the database, and expects the result that comes with the event handler is processed in the application).

protected object ExecuteCommand(SvcCmdType cmdType, params object[] inputParams)
{
  // this code has been simplified
  SvcCommandEventArgs eventArgs = new SvcCommandEventArgs(cmdType, inputParams);

  // generate processing command event (it requires to fill in the result)
  OnProcessingAppCommand(this, eventArgs);

  return eventArgs.OutputParamsList; 
}

Problem :

C1 C2 ExecuteCommand , , , .

? ExecuteCommand, , AsyncOperation... ?

: , : ? , - ?

.

.

+3
1

- (, , ). :

http://msdn.microsoft.com/en-us/library/c5kehkcz(VS.71).aspx

"this", , , . .

/ :

class SomeClass : ISomeInterface
{
  protected object ExecuteCommand(SvcCmdType cmdType, params object[] inputParams)
  {
    lock(executeCommandLock)
    {
      SvcCommandEventArgs eventArgs = new SvcCommandEventArgs(cmdType, inputParams);
      OnProcessingAppCommand(this, eventArgs);
      return eventArgs.OutputParamsList; 
    }
  }

  private Object executeCommandLock = new Object();
}

Edit:

( ). , ExecuteCommand . Dispatcher:

http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.aspx

. . ExecuteCommand, .BeginInvoke. BeginInvoke, ExecuteCommand , . , ExecuteCommand .

+1

Source: https://habr.com/ru/post/1758868/


All Articles