Quantcast
Channel: CodesMesh » Syed Wajahat Ali Shah
Viewing all articles
Browse latest Browse all 11

Threading in C# with example

$
0
0

Thread 

Thread is the smallest piece of program that can be managed by operating system. A process may consist of many threads. Threads run concurrently. Basically they work in queue which is scheduled by operating system. For a small amount of time processor’s resources are given to one thread then to another. While one thread is being executed others wait in a queue and when any other thread is to get executed the data and content associated with current thread is stored in a memory stack which is replaced in processor’s register when that thread is called to be executed.

Threads in C#:

Thread Declaration

Threads are declared in C# using System.threading() and then using following command


where callBackFunction is the function that will be called when this thread starts executing.

Thread Initialization

A thread can be started once declared using thread.start() function

Thread Abortion

A thread is aborted using thread.abort() funciton

Thread Suspension & restoration

To suspend a thread for a while for like calling another one we use thread.suspend()


To resume this thread we use

C# Code for threads:

Following is a code for multiple thread execution its very simple and self explaining for any query comment below it will be appreciated. Thanks


Viewing all articles
Browse latest Browse all 11

Trending Articles