In framework 4 the Tasks library in introduced.

With the TPL ( task parallel libary ) it's more simple to create synchronous or asynchronous threads and keeps control over it.

The most likely use for Tasks is executing multiple methods on different threads at once. Like this:

WaitAll

Task[] tasks = new Task[3]
{
    Task.Factory.StartNew(() => MethodA()),
    Task.Factory.StartNew(() => MethodB()),
    Task.Factory.StartNew(() => MethodC())
};

Task.WaitAll(tasks);

WhaitAny

In comparison to WaitAll wich waits for all methods, WaitsAny waits for any methods before it proceeds to next.

WhenAll

WhenAll is used with chaining:

            Task[] tasks = new Task[3]
            {
                Task.Factory.StartNew(() => CountTo100()),
                Task.Factory.StartNew(() => CountTo200()),
                Task.Factory.StartNew(() => CountTo900())
            };
            try
            {
                Task.WhenAll(tasks).ContinueWith( (IAsyncResult =>
                    {
                        // dosomething with the result
                    });
            }
            catch (AggregateException aggregationexception)
            {
                foreach (Exception exception in aggregationexception.InnerExceptions)
                {
                    throw exception;
                }
            }

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!