First, let's close the problem of events. You cannot ever invoke an event from anywhere except the declaring type of that event, not even from derived class. This is an important fool-proof feature of .NET. Most likely, you mean the event declared in some .NET FCL type. If so, you have no a way to invoke it then, except the ways it is already being invoked (mouse click, and so on). And you never really need to do it. I explained it all in my past answers:
Calling an Event as a Function in C++ CLI[
^],
c# networking windows form[
^].
If you explain to me what you though to achieve by invoking the event, I'll tell you what you really need to do.
Now, please see my comment to the question; you should have specified what you main thread is doing. If this is a thread of a WPF application or
System.Windows.Forms.Application
, the answer is simple:
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
If your main thread is something different, you would need to design the thread method to implement similar behavior. Only then you will be able to delegate anything to that thread. I explained how to do it in my article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
If you are using .NET 4.0 or later, you can use more efficient class
System.Collections.Concurrent.BlockingCollection<T>
:
http://msdn.microsoft.com/en-us/library/dd267312%28v=vs.110%29.aspx[
^].
Note that
T
can be a delegate, to implement the mechanism very close to
Invoke/BeginInvoke
. Again, read my article referenced above, to see how to do it.
So, I think you got a 100% comprehensive answer this time, but, next time, pay attention for my comment to the question and provide more relevant information.
—SA