Monotouch Threading - Best Design

Often I need to perform an expensive task and then display the results. Therefore, I am increasing the flow. Is there less code or a better way to do this than I am currently using?

Example:

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

- run this thread here ....

+3
source share
2 answers

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

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

+6
source

As Kevin points out, using ThreadPool is a little easier.

But there is an added bonus to using ThreadPool: Mono will limit the number of threads that you deploy, which will help you better save limited resources on your device.

+4
source

Source: https://habr.com/ru/post/1775766/


All Articles