What is the difference between a thread/process/task?

Process: A process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently. Process-based multitasking enables you to run the Java compiler at the … Read more

Proper way of handling exception in task continuewith

You probably don’t need separate OnlyOnFaulted and OnlyOnRanToCompletion handlers, and you’re not handling OnlyOnCanceled. Check this answer for more details. But when debugging in IDE, A IDE exception message (“Unhandled exception in user code” ) appears when the control executes the line You see the exception under debugger because you probably have enabled it in … Read more

Asynchronous Task.WhenAll with timeout

You could combine the resulting Task with a Task.Delay() using Task.WhenAny(): await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(timeout)); If you want to harvest completed tasks in case of a timeout: var completedResults = tasks .Where(t => t.Status == TaskStatus.RanToCompletion) .Select(t => t.Result) .ToList();

C# – ThreadPool vs Tasks

The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible. The implementation uses a TaskScheduler object to control the handling of tasks. This has virtual methods that you can override to create your own task handling. Methods include for instance protected virtual void … Read more

Is Task.Factory.StartNew() guaranteed to use another thread than the calling thread?

I mailed Stephen Toub – a member of the PFX Team – about this question. He’s come back to me really quickly, with a lot of detail – so I’ll just copy and paste his text here. I haven’t quoted it all, as reading a large amount of quoted text ends up getting less comfortable … Read more

await Task.Delay() vs. Task.Delay().Wait()

The second test has two nested tasks and you are waiting for the outermost one, to fix this you must use t.Result.Wait(). t.Result gets the inner task. The second method is roughly equivalent of this: public void TestAwait() { var t = Task.Factory.StartNew(() => { Console.WriteLine(“Start”); return Task.Factory.StartNew(() => { Task.Delay(5000).Wait(); Console.WriteLine(“Done”); }); }); t.Wait(); … Read more

How do I add a high-priority TODO comment in Visual Studio?

The priority of the task depends on the keyword you use to tag it. You can see and edit a list of keywords and their priorities by going to Tools->Options->Environment->Task List. For example, on my installation, I’ve got HACK, TODO and UNDONE as normal priority, and UnresolvedMergeConflict as high priority. If you want to add … Read more

Why is Task not co-variant?

According to someone who may be in the know… The justification is that the advantage of covariance is outweighed by the disadvantage of clutter (i.e. everyone would have to make a decision about whether to use Task or ITask in every single place in their code). It sounds to me like there is not a … Read more