events and threading

G

Guest

Hi there,
i have an object O1 in a thread context C1. This object BeginInvokes() a
loop-oriented method M2 on a second object O2 thereby creating a new thread
context C2 for O2.M2. O1 has before registered on an event eventually fired
by O2.M2. This eventually results in executing the handler function O1.H1 on
thread context C2. This is not thread safe without some provision. Can i
force the execution thread of the handler O1.H1 back to C1 as it is done by
Control.BeginInvoke(). The event firing in O2.M2 is done using some
construction like handler.BeginInvoke() but i suppose this doesnt help.
Thanks for your help
Peter
 
J

Jon Skeet [C# MVP]

<"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam
please)> said:
I don't know but maybe the following article will help you:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfo
rms/html/winforms06112002.asp

That article hass an unfortunate bug in, however - it's calling
BeginInvoke on a delegate and never calling EndInvoke, which could lead
to a leak. (Calling Control.BeginInvoke without a matching EndInvoke is
okay though.)

See http://www.pobox.com/~skeet/csharp/threads/threadpool.shtml
for more details of this.
 
S

Sylvain Lafontaine

Thanks,

I didn't have the occasion to take a look at the multithread
capabilities of DotNet yet - because I'm only working with ASP.NET at the
moment - but surely I will look at this article when I will take the plunge.

S. L.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Thread safety of events 16
C# threading, events and main thread. 11
Threading and raising events 4
Events and threads 7
Windows Form Threading 9
Cannot access disposed object 3
Threading a server 8
Threading WinForm 8

Top