Asynchronous methods, Invoke

  • Thread starter Thread starter Christian Westerlund
  • Start date Start date
C

Christian Westerlund

Hi!

From one of my worker threads I want to update the UI so I
use myControl.Invoke but I want the worker thread to continue work after
that but with Invoke the worker thread blocks until the method returns.
I know of BeginInvoke but that isn't available in .NET CF.

Is there another method I can use to solve this problem.

/Christian
 
At the point where you wish to call BeginInvoke, use the ThreadPool to
callback one of your methods and in that method call Control.Invoke...

Cheers
Daniel
 
Ok, I got it to work with ThreadPool.QueueUserWorkItem but it seems to
be a little too much to create another thread just to run a single
method. Aren't there any other function which one can use for this purpose?

/Christian
 
Hi Christian

BeginInvoke on the desktop framework does the same thing (i.e. utilise a
thread from the ThreadPool)... If the framework works as advertised you
should find that the pool reuses threads rather than creating new ones each
time... Note that unlike the desktop framework, the number of threads on CF
is not limited to 25... Anyway I use this technique with no problems...

Alternatively you may wish to check out
http://www.develop.com/compactframework/ and in particular the "UI Safe
Invoker" under samples... Never used it myself but looks promising...

Cheers
Daniel
 
Back
Top