Category Archive for: Threading and Synchronization

Synchronization

It is best to avoid synchronization issues by not sharing data between threads. Of course, this is not always possible. If data Sharing is necessary, you must use synchronization techniques so that only one thread at a time accesses and changes shared state. Remember the s~tion issues with race conditions and deadlocks. If you don’t pay attention…

Read More →

Threading Issues

Programming with multiple threads is not easy. When starting multiple threads that access the same data, you can get intermittent problems that are hard to find. To avoid getting into trouble, you must pay attention to synchronization issues and the problems that can happen with multiple threads. Wediscuss two in parti~ next race conditions and deadlocks .. Race…

Read More →

Thread Pools

Creating threads takes time. When you have different short tasks to do, you can create a number of threads in advance and send requests as they should be done. It would be nice if this number increased as more threads were needed and decreased as needed to release resources. There is no need to create such a…

Read More →

Passing Data to.Threads

There are two ways to pass some data to a thread. You can either use the Thread constructor with the ParameterizedThreadStart delegate, or you can create a custom class and define the method of the thread as an instance method so that Y0′:l can initialize data of the instance before starting the thread. For passing data to a…

Read More →

The Thread Class

With the Thread class you can create and control threads. The code here is a very simple example of creating and starting a new thread. The constructor of the Thread class accepts a delegate parameter of type ThreadStart and Parameteri zedThreadStart. The ThreadStart delegate defines a method with a void return type and without arguments. After the…

Read More →

Asynchronous Delegates

A simple way to create a thread is by defining a delegate and invoking the delegate asynchronously. In Chapter 7, “Delegates and Events,” you saw delegates as type-safe references to methods. The Delegate class also supports invoking the methods asynchronously. Behind the scenes, the Delegate class creates a thread that fulfills the task. The delegate uses a thread…

Read More →

Overview

A thread is an independent stream of instructions in a program. All your C# programs up to this point have one entry point – the Main () method. Execution starts with the first statement in the Main ( ) method and continues until that method returns. • This program structure is all very well for programs, in which…

Read More →

Threading and Synchronization

There are several reasons for using threading. Suppose that you are making a network call from an application that might take some time. You don’t want to stall the user interface and just let the user wait until the response is returned from the server. The user could do some c ~er actions in the m.eantime or even…

Read More →

Back to Top