Hi guys,
I need somebody with high skills in threading and event raising.
I have an abstract class A and two concrete classes C1, C2 (e.g plugins).
Since I need them to communicate between each other, like "plugin-application" "plugin-plugin" communication, I have a method ExecuteCommand in the abstract class which should accomplish this. This function raises an event to the application in order to process a certain command and return the result (e.g if one plugin needs data from the app it calls ExecuteCommand from the base and waits for the result which comes with the event handler processed on 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;
}
The problem is:
If each one of C1 and C2 have different threads behind and call simultaneously ExecuteCommand from inside their own threads then for sure my design will be broken and the result returned will be unexpected.
What is the best design for this scenario? I was thinking to use inside ExecuteCommand asynchronous calls like using AsyncOperation... but is it the right way?
edited: I guess I am looking for: is the synchronous or asynchronous way better for my scenario? Or, shall I have the app event handler processed inside a plugin's thread or synchronized somewhere in my main thread?
I would really appreciate some good explanations for your recommendations
Thank you.