Home All Groups Group Topic Archive Search About

Same event fired from 2 different threads..?

Author
26 Nov 2007 3:38 PM
tjo
Hi

I have a short question regards event i C#.

I have two C# threads. The can both fire the same event idepended of
each other.

How is this hande by the CLR? Are the calls queued?

Thread1()
{

}

Author
26 Nov 2007 3:42 PM
tjo
On 26 Nov., 16:38, t***@agramkow.com wrote:
Show quote
> Hi
>
> I have a short question regards event i C#.
>
> I have two C# threads. The can both fire the same event idepended of
> each other.
>
> How is this hande by the CLR? Are the calls queued?
>
> Thread1()
> {
>
>
>
> }- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -

Sorry... Here is the rest..

//Thread class
Thread1()
{
   ....
   if(OnPacket != null)
       OnPacketr();
   ...
}


Thread2()
{
   ....
   if(OnPacket != null)
       OnPacketr();
   ...
}


// Main class
Main()
{
   .....
   myClass.OnPacket += new OnPacket(eventHandler);
}

eventHandler()
{

}

If the Thread1 and Thread2 fires the event at the same time, how does
the CLR handle this?
Author
26 Nov 2007 3:56 PM
Scott Roberts
> I have two C# threads. The can both fire the same event idepended of
> each other.
>
> How is this hande by the CLR? Are the calls queued?

The event-handler is executed in the same thread as where the event is
fired. So in your example, the code in the event-handler will execute
simultaneously in two different threads.

AddThis Social Bookmark Button