I’ve a static class called Service which starts a new thread to keep listening message from other process. In this class I manage a list of delegates which needs to be invoked when a message is received. Some of the methods of these delegates need to run in the main thread.
If I would create the threat in some form, for example, I could just do
this.Invoke(@delegate, new object[] { messageReceived });
But I can’t do that because I’m in a static class. So I tried doing like this:
@delegate.Invoke(messageReceived);
But it doesn’t work because it doesn’t change the subprocess where the method is executed (it is executed from my created threat, not from the main one).
How can I do?
Thanks!
Modify your
staticclass to accept a parameter.Pass your
thisvariable as a parameter to yourstaticclass.