B
Boris Drajer
Hi,
I'm trying to create a method on my windows form that starts a
multi-threaded task, waits for it to finish, and then returns.
To be more precise: the form has a LoadUrl() method. This method calls
the Navigate() method on the form's embedded WebBrowser control, and
then does a WaitOne() on a ManualResetEvent. This ManualResetEvent will
be Set() from WebBrowser's DocumentComplete handler when loading is done.
So, what happens is this: when Navigate() is called, the web browser
starts the download in a secondary thread and returns, thus jumping to
my WaitOne() call where I wait for it to finish. While downloading, the
browser wants to update the UI, which has to be done from the primary
thread. But no dice, the WaitOne() call is blocking it.
Now, I must do some kind of Wait() on the primary thread because I want
to return from the method only when the operation is complete. But, I
somehow have to wait without blocking this thread. Is this possible?
It seems that the windows form has a solution to this. How does the form
manage this primary thread so it knows how to do BeginInvoke, for
example? Do I need to use the message loop or something?
Any hint is welcome. Thanks in advance!
I'm trying to create a method on my windows form that starts a
multi-threaded task, waits for it to finish, and then returns.
To be more precise: the form has a LoadUrl() method. This method calls
the Navigate() method on the form's embedded WebBrowser control, and
then does a WaitOne() on a ManualResetEvent. This ManualResetEvent will
be Set() from WebBrowser's DocumentComplete handler when loading is done.
So, what happens is this: when Navigate() is called, the web browser
starts the download in a secondary thread and returns, thus jumping to
my WaitOne() call where I wait for it to finish. While downloading, the
browser wants to update the UI, which has to be done from the primary
thread. But no dice, the WaitOne() call is blocking it.
Now, I must do some kind of Wait() on the primary thread because I want
to return from the method only when the operation is complete. But, I
somehow have to wait without blocking this thread. Is this possible?
It seems that the windows form has a solution to this. How does the form
manage this primary thread so it knows how to do BeginInvoke, for
example? Do I need to use the message loop or something?
Any hint is welcome. Thanks in advance!