Re: Async thread not freeing up UI
- From: "Brian Gideon" <briangideon@xxxxxxxxx>
- Date: 11 Dec 2005 14:34:25 -0800
Mark,
The first thing I noticed was that you're accessing a Control on a
thread other than the one it was created on. This will cause
unpredictable problems on the 1.1 framework and an exception on the 2.0
framework. You need to use Control.Invoke to marshal the execution of
a delegate onto the UI thread so that you can access controls and forms
safely within that delegate.
Another thing I noticed is that you're spinning in a loop waiting for
the Matrix_Multiply method to complete. That will certainly consume a
lot of CPU time and make the UI somewhat unresponsive.
However, it doesn't appear that the UI would be completely unresponsive
since the UI thread isn't blocked by any of the code you posted.
Brian
mark wrote:
> Please consider the following thread setup intended to free-up the UI while a
> huge process takes place:
>
> (declare delegates) (A B and C all global)
>
> Private Sub AB_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles AB.Click
> Dim NoArg1 As New NoArgs(AddressOf AxB)
> NoArg1.BeginInvoke(Nothing, Nothing)
> End Sub
>
> Private Sub AxB()
> Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
> Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A, B, Nothing,
> Nothing)
> Do Until AsyncResult.IsCompleted
> For i = 1 To 1000000 : Next : Button3.Text = Rnd().ToString
> Loop
> C = mult.EndInvoke(AsyncResult)
> do other stuff with C
> End Sub
>
> Matrix_Multiply is the class solver and consumes 50% of CPU resources with a
> hyperthreading P4. It is floating point arithmatic intensive. When I run the
> program the UI is unavailable until the final C result - which is double(,) -
> is obtained. Button3.text initially shows activity but then stops. The
> threading logic works fine with a local function that simply runs a loop then
> returns a string.
>
> What's wrong? How fix?
> --
> mark b
.
- Follow-Ups:
- Re: Async thread not freeing up UI
- From: mark
- Re: Async thread not freeing up UI
- Prev by Date: Dataadabter update command throws error
- Next by Date: Re: Best way to have a tabbed MDI application
- Previous by thread: Re: Async thread not freeing up UI
- Next by thread: Re: Async thread not freeing up UI
- Index(es):