I have a thread, I need to call a void like this :
makegraph(toplot, ite, mm_0)
However if I want to synchronize I should use SynchronizationContext and do :
SynchronizationContext mContext = null;
mContext.Post(new SendOrPostCallback(makegraph(toplot, ite, mm_0)),null);
But I have the followinf error : Method name expected .
I know that I should use delegates but I am not familiar with the syntax.
Can you help me on that please ?
First off, your
mContextvariable is never set to an instance ofSynchronizationContext, it’s initialized to null.The function SynchronizationContext.Post() expects two arguments, one of type SendOrPostCallback, and one of type object.
object stateparameter of the Post function is the parameter that will get passed into the delegate specified in the first paramter.That means, you will need to make a new
makegraphfunction that matches the signature of the SendOrPostCallback delegate, and then pass in all of the paramters in a single object, like so:You could then use this code like so:
In addition, you can just pass in your method name for the delegate as a shortcut:
For more info on delegates, see the MSDN article Delegates (C# Programming Guide)
.