I want to invoke a method that manipulates a control on the UI thread. My code works and I want to optimize. I am referring to this resource on MSDN.
According to there, we should do
public delegate void myDelegate(int anInteger, string aString);
//...
Label1.Invoke(new myDelegate(myMethod), new Object[] {1, "This is the string"});
Would this introduce an orphaned delegate object (a memory leak), at each call?
When I would do it with a static instance of the delegate like below and then use this instance at each call to invoke:
private static _delegateInstance = new myDelegate(myMethod);
//...
Label1.Invoke(_delegateInstance , new Object[] {1, "This is the string"});
Would this be Thread-Safe? I would it be true that this has a slightly better performance, since the delegate instance is only created once?