Hi I'm working with threads and events. Several threads of a method in my
code can launch a event that will be captured by only one component (another
class).
This is a problem to me?? There is a stack of events that will be executed
sequentially??
Thanks.
From this perspective an event is really no different from any other method.
There is no automatic synchronization on the event (i.e. no stack of
events) - so an event procedure can be executing on more than one thread at
the same time. As with all methods the local variables and parameters will
be created on the thread's stack and so will be safe from any threading
effects. But if you are accessing any module level (or global) variables or
non-threadsafe methods in your event procedure or if any of the local
variables refer (directly or indirectly) to a module level object then you
must use normal thread synchronization techniques, such as events, mutexes
or locks, to guard against race conditions and invalid data structures, etc.
> Hi I'm working with threads and events. Several threads of a method in my
> code can launch a event that will be captured by only one component (another
[quoted text clipped - 8 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.520 / Virus Database: 318 - Release Date: 18/9/2003
msnews.microsoft.com - 23 Sep 2003 05:05 GMT
As an interesting aside to this: If you set timers to run methods in your
app, you should really lock that method unless you are absolutely certain
nothing bad could happen. If you put that method in a lock (this) block
you're safe and the requests just stack up and wait in line. On the
off-chance that the timer cycles while you're still executing the method it
could be quite ugly. I guess I never thought of a timer being a
multi-threaded operation but I learned the hard way.
Wes
> From this perspective an event is really no different from any other method.
> There is no automatic synchronization on the event (i.e. no stack of
[quoted text clipped - 20 lines]
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.520 / Virus Database: 318 - Release Date: 18/9/2003
Francisco K. do Amaral - 25 Sep 2003 17:45 GMT
Ok, I understand that the method that handle the event will execute in the
same context of the thread that lauch it.
So, how can I make the handle method to be another thread?
thanks.
> From this perspective an event is really no different from any other method.
> There is no automatic synchronization on the event (i.e. no stack of
[quoted text clipped - 20 lines]
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.520 / Virus Database: 318 - Release Date: 18/9/2003