Tag: Parallel Programming

Book Review: Threading in C# by Joseph Albahari

Book Review: Threading in C# by Joseph Albahari

Threading is a complex subject, it is easy to get yourself entangled in threads which don’t behave as you expect them to. There are many constructs and approaches to synchronize threads or achieve parallelism, each with its own quirks and advantages. There are good old threads, there are thread pools, task parallelism, Parallel class, Async…

Read More Read More

Async / Await and SynchronicationContext (C# .Net)

Async / Await and SynchronicationContext (C# .Net)

Following innocuous looking async / await code will cause deadlock. To understand why, lets go into what await does in the above case. 1 Execution starts when the button is clicked and button1_Click event is fired on the UI thread. 2 The method, named LongRunningProcess, is invoked. 3 The lamda expression passed to Task.Run() executes in…

Read More Read More

Creating and Consuming Async methods (C# .Net)

Creating and Consuming Async methods (C# .Net)

The code we want to run asynchronously could either be CPU-bound or IO-bound. CPU-bound code keeps the CPU busy, requiring intensive processing, calculations etc. On the other hand, IO-bound code frees up the CPU while waiting for an IO operation to complete, for instance, get some data from a web service. Both kinds of asynchronous…

Read More Read More

Keeping UI Responsive (C# .Net)

Keeping UI Responsive (C# .Net)

The User Interface (UI) becomes unresponsive when a time taking operation is executed during an event. Consider the following button click event where I have simulated a time taking operation by calling Sleep method. In a real scenario, it could be some processing which produces the result to be shown back on the user interface.…

Read More Read More