Ian Vink
Ian Vink

Reputation: 68750

Monotouch Threading - Better Design Question

Often, I need to do an expensive task then display results. So I ramp up a thread. Is there less code, or a better way to doing this than I am currently using?

Example:

ThreadStart job = new ThreadStart (delegate {
    Search d = new Search ();
    x = d.DoSomeWork();
    InvokeOnMainThread (delegate {
         ctl.Show (x);
          });
});

--start the thread here....

Upvotes: 3

Views: 1747

Answers (2)

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

As Kevin points out, the use of the ThreadPool is slightly simpler.

But there is an added bonus to using the ThreadPool: Mono will limit the number of threads that you spin up, helping you better preserve the limited resources on the device.

Upvotes: 4

Kevin McMahon
Kevin McMahon

Reputation: 2644

You can use the thread pool and simplify things a little bit.

ThreadPool.QueueUserWorkItem( delegate { /* ... */ } );

Upvotes: 6

Related Questions