Re: multiple threads writing to WebBrowser, getting deadlocked



Zytan <zytanlithium@xxxxxxxxx> wrote:

<snip>

For the curious:

Move the Thread.Sleep(400) to AFTER the MyWrite call, and it works,
always. Thanks to Jon's great reply, I now know why. This single
difference was the difference between two identical apps I made, and I
was dumbfounded as to why one worked and the other didn't.
Thread.Sleep() at the end doesn't give the deadlock of Control.Invoke
and Thread.Join to occur.

Hmm. You've still got a potential deadlock, unfortunately.

If you click the stop button at just the wrong time, it will still
break. You can end up with btnStop_Click running, waiting for myThread
to finish - but with myThread waiting for a call to web.Invoke to
finish.

Using BeginInvoke is certainly a reasonable way of avoiding this,
although I'd avoid calling Thread.Join in the UI thread too.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.


Loading