Total Downloads

2,603,486

Total Files

9,206

Latest Update

10

How to work with threads in C#

Posted August 13, 2018 | Windows


A thread is the smallest unit of execution within a process. Multithreading is the ability to have multiple threads in memory at a given time and switch among them to handle multiple operations at the same time. Microsoft’s .Net Framework provides excellent support for working with threads.

Programming threads in C#

To work with threads, you should include the System.Threading namespace in your application. To create a new thread, you should leverage the ThreadStart delegate and pass the reference to a method that should execute on the thread. Note that a delegate is a type-safe function pointer. The following code snippet shows how you can create a new thread object using this delegate.

Thread t = new Thread(new ThreadStart(MyThreadMethod));

To start the newly created thread, you should call the Start method on the thread object you have created. The following code listing illustrates this. Note that the thread method MyThreadMethod executes on the new thread (called a worker thread) that has been created.



Source link

')
ankara escort çankaya escort çankaya escort escort bayan çankaya istanbul rus escort eryaman escort ankara escort kızılay escort istanbul escort ankara escort ankara escort escort ankara istanbul rus Escort atasehir Escort beylikduzu Escort Ankara Escort malatya Escort kuşadası Escort gaziantep Escort izmir Escort