X

Multi-tasking

It is a concept of performing multiple tasks over a certain period of time by executing them concurrently.

Multi-threading

It forms subset of Multi-tasking. It is the ability of a program to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer.

Thread

It is a thread of execution in a program. One or more threads run in an AppDomain. An AppDomain basically provides an isolated region in which code runs inside of a process. Each AppDomain is started with a single thread, but can create additional threads from any of its threads. ‘System.Threading’ has all the classes related to implement threading. Any .NET application which wants to implement threading has to import this namespace.

Thread.Join()

There are three versions of Thread join-

·         Thread.join().

·         Thread.join(int) this returns a bool value.

·         Thread.join(TimeSpan) this returns a bool value.

The Thread.Join method is useful to determining if a thread has completed before starting another task. The Join method waits a specified amount of time for a thread to end. If the thread ends before the time-out, Join returns true; otherwise it returns false. Once we call join, the calling procedure stops and waits for the thread to signal that it is done.

Thread.Join(int) and Thread.Join(TimeSpan) ensures that threads do not wait for a long time. If it exceeds a specific time, which is provided in integer or timespan the waiting thread will start.

Interlocked Class

It provides methods which help protect against errors that can occur when the scheduler switches contexts when two threads are executing concurrently on separate processors.

Monitor Object

Monitor objects expose the ability to synchronize access to a region of code by taking and releasing a lock on a particular object using the Monitor.  Lock statement is provided in order to simplify access to monitor object.

Wait Handles

The WaitHandle class encapsulates Win32 synchronization handles, and is used to represent all synchronization objects in the runtime that allow multiple wait operations. There are three kind of wait modes:

·         WaitOne

·         WaitAny

·         WaitAll

When a thread wants to release a Wait handle it can call set method. We can use mutex objects to avail for the following modes. Mutex objects are synchronization objects whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned. Threads request ownership of the mutex object when they require exclusive access to a resource because only one thread can own a mutex object at any time, other threads must wait for ownership of a mutex object. If a thread terminates normally while owning a mutex object, the state of the mutex object is said to be signaled and the next waiting thread gets ownership.

ManualResetEvent and AutoResetEvent

Threads that call one of the wait methods of a synchronization event must wait until another thread signals the event by calling the Set method. There are two synchronization event classes. Threads set the status of ManualResetEvent instances to signaled using the Set method. Threads set the status of ManualResetEvent instances to no signaled using the Reset method or when control returns to a waiting WaitOne call. Instances of the AutoResetEvent class can also be set to signaled using Set, but they automatically return to no signaled as soon as a waiting thread is notified that the event became signaled.

Reader Writer Locks

We may want to lock a resource only when data is being written and permit clients to simultaneously read data when data is not being updated. The ReaderWriterLock class enforces exclusive access to a resource while a thread is modifying the resource, but it allows nonexclusive access when reading the resource. Reader Writer Locks are a good alternative to exclusive locks that cause other threads to wait, even when those threads do not need to update data.

A good and careful planning can avoid deadlocks. There are so many ways Microsoft has provided by which we can reduce deadlocks.

Thread and Process

A process, in the simplest terms, is an executing program. One or more threads run in the context of the process.

Implementation

        protected void Button1_Click(object sender, EventArgs e)

        {

            Thread pthread1 = new Thread(Thread1);

            Thread pthread2 = new Thread(Thread2);

            pthread1.Start();

            pthread2.Start();

        }

 

        public void Thread1()

        {

            int pint = 0;

            string pstr;

            pstr = "This is first thread";

            do

            {

                lstThreadDisplay.Add(pstr);

                pint = pint++;

            }

            while (pint < 5);

        }

 

        public void Thread2()

        {

            int pint = 0;

            string pstr;

            pstr = "This is second thread";

            do

            {

                lstThreadDisplay.Add(pstr);

                pint = pint++;

            }

            while (pint < 5);

        }

    }

Thread Priority can be changed by using

Threadname.Priority = ThreadPriority.Highest;

Following are different types of Priority provided by .NET:

ThreadPriority.Highest;

ThreadPriority.AboveNormal;

ThreadPriority.Normal;

ThreadPriority.BelowNormal;

ThreadPriority.Lowest;

 

“Thread.CurrentThread” refers to the current thread running in the method. “CurrentThread” property is used to display information about the thread on which it is running. Thread’s execution can be paused by calling the Thread.Sleep method. This method takes an integer value that determines how long the thread should sleep. We can also place a thread into the sleep state for an indeterminate amount of time by calling Thread.Sleep(Timeout.Infinite);. To interrupt this sleep we can call the Thread.Interrupt method. Thread.Abort() stops the thread execution at that moment itself.

 

Debug

 

Debug thread

This window is only seen when the program is running in debug mode. In windows one of the windows is “Threads”.

 

Daemon Threads

Daemon thread runs in background and it stop automatically when the program is not running. We can make a thread Daemon by Thread.IsBackground = true;

There are certain situations that we need to be careful with when using threads. If two threads try to access the same variable at the same time, we’ll have a problem. This can be very difficult to debug because they may not always do it at exactly the same time. To avoid the problem, we can lock a variable before accessing it. However, if the two threads lock the same variable at the same time, we will have a deadlock problem. To avoid dead lock we need to use the ‘lock’ keyword as shown below.

lock (x)

{

 

}

 

To synchronize one thread with other we can use events.

 

“ThreadState” property can be used to get detail of a thread. Thread can have one or a combination of status. ‘System.Threading.ThreadState’ enumeration has all the values to detect a state of thread.

TPL

It stands for Task Parallel Library. It is a set of public types and API’s in the System.Threading and System.Threading.Tasks namespaces. When we use threading API directly we need to take care of pooling, ensure that thread executes on multiple processors, data and task parallelism etc. When we use TPL all these things are taken care of so that we concentrate on the work rather than these lower level technical details.

It simplifies the following things from development aspect:

·         Thread pooling is taken care internally.

·         It ensures that threads will execute on multiple processors.

·         Cancellation of threads made easier.

·         State management simplified as compared to core threading.

It’s all components exists in the below namespace.

using System.Threading.Tasks;

 

To invoke a thread using it we need to use the below syntax. We need to create the object of task object to invoke a thread.

Task tsk = new Task(Mytask);

tsk.Start();

 

 

 

Related

Connect apps and integrate data with workflows using Azure Logic Apps

Implementing complex business process has been made easy. Logic Apps in azure provide a way to imple...

Read More >

TFS to VSTS Migrations

The next evolution of TFSWhether you’re a startup or Enterprise or you’re a team of just...

Read More >

CfMD services -Dynamics NAV

CfMD services help ISVs minimize the time and effort needed to get their software solution through t...

Read More >

Upcoming Webinar - Offshore support to North American Dynamics NAV partners

Offshore support to North American Dynamics NAV partners whose customers are moving to NAV '16Wh...

Read More >

Microsoft Azure Consultant

·         Executing technical feasibility as...

Read More >

Customer Feedback

Your feedback is important to us. Please share your experience working with Canarys & the journe...

Read More >

Partnership Program

We understand that the world of technology is changing rapidly from day to day and businesses have m...

Read More >

Partnership Program

The Canarys Partner Program:Canarys is all set to expand its business reach across the Globe and is ...

Read More >

Upcoming Webinar US - Plugging for Cloud, Right or Wrong

Plugging for Cloud, Right or Wrong?Cloud computing continues to be one of the most advertising topic...

Read More >

Webinar US - Plugging for Cloud, Right or Wrong?

Plugging for Cloud, Right or Wrong?Cloud computing continues to be one of the most advertising topic...

Read More >

Share

Comments

https://www.omgab.com/first 퍼스트카지노
7/19/2021 6:38:29 AM | Reply
https://www.oobbg.com/33 33카지노
7/19/2021 6:38:19 AM | Reply
우리카지노사이트예스카지노퍼스트카지노더킹카지노메리트카지노샌즈카지노조이카지노로얄카지노스타클럽카지노 아시안카지노슈퍼맨카지노개츠비카지노33카지노온라인카지노우리카지노사이트퍼스트카지노더킹카지노메리트카지노샌즈카지노33카지노월드카지노코리아카지노우리카지노사이트샌즈카지노예스카지노퍼스트카지노더킹카지노33카지노월드카지노슈퍼카지노코리아카지노개츠비카지노우리카지노사이트퍼스트카지노메리트카지노더킹카지노샌즈카지노예스카지노개츠비카지노코리아카지노33카지노f1카지노우리카지노사이트메리트카지노퍼스트카지노샌즈카지노예스카지노개츠비카지노더킹카지노
6/30/2021 11:39:36 AM | Reply
https://www.ekffo150.com 우리카지노사이트
6/30/2021 11:34:30 AM | Reply
https://www.ekffo150.com/thekinghttps://www.ekffo150.com/merithttps://www.ekffo150.com/yeshttps://www.ekffo150.com/firsthttps://www.ekffo150.com/sandshttps://www.ekffo150.com/joyhttps://www.ekffo150.com/royalhttps://www.ekffo150.com/starclubhttps://www.ekffo150.com/asianhttps://www.ekffo150.com/supermanhttps://www.ekffo150.com/gatsbyhttps://www.ekffo150.com/33https://www.ekffo150.com/oncasinohttps://www.ekffo150.com https://www.ajp4949.com/thekinghttps://www.ajp4949.com/merithttps://www.ajp4949.com/sandshttps://www.ajp4949.com/firsthttps://www.ajp4949.com/33casinohttps://www.ajp4949.com/worldcasinohttps://www.ajp4949.com/koreahttps://www.ajp4949.com/https://www.bgj4949.com/https://www.bgj4949.com/sandshttps://www.bgj4949.com/thekinghttps://www.bgj4949.com/firsthttps://www.bgj4949.com/yeshttps://www.bgj4949.com/33https://www.bgj4949.com/worldhttps://www.bgj4949.com/superhttps://www.bgj4949.com/koreahttps://www.bgj4949.com/gatsbyhttps://www.dnfl4949.com/https://www.dnfl4949.com/firsthttps://www.dnfl4949.com/merithttps://www.dnfl4949.com/thekinghttps://www.dnfl4949.com/sandshttps://www.dnfl4949.com/yescasinohttps://www.dnfl4949.com/gatsbyhttps://www.dnfl4949.com/coreahttps://www.dnfl4949.com/33casinohttps://www.dnfl4949.com/f1casinohttps://www.skfl4949.com/https://www.skfl4949.com/firstcasinohttps://www.skfl4949.com/meritcasinohttps://www.skfl4949.com/sandscasinohttps://www.skfl4949.com/thekingcasinohttps://www.skfl4949.com/yescasinohttps://www.skfl4949.com/gatsbycasino
6/30/2021 11:29:12 AM | Reply
바카라사이트 검증_ https://casinojoin77.blogspot.com/2021/05/the-best-casinosite-without-license-in.html바카라_ https://marryann1220.blogspot.com/2021/05/5-games-easiest-to-win-in-casino-site.html바카라사이트 추천_ https://marryann1220.blogspot.com/2021/05/blog-post_4.html바카라 규칙_ https://marryann1220.blogspot.com/2021/05/blog-post.html바카라 시스템 배팅_ https://marryann1220.blogspot.com/2021/04/blog-post_21.html바카라 기본용어_ https://marryann1220.blogspot.com/2021/04/blog-post_28.html바카라 _ https://casinojoin77.blogspot.com/2021/05/blog-post_4.html바카라사이트 검증_ https://casinojoin77.blogspot.com/2021/04/blog-post_22.
6/28/2021 1:35:32 PM | Reply
샌즈카지노 Some Sic Bo bets are highly risky but, at the same time, they award large prizes. For instance, specific triple bets award 180 to 1 but their house edge sits at 16.2%. Another type of bet in Sic Bo you should avoid is a specific dice combination. While it pays a prize of 50 to 1, it has a huge house edge of 29.2%.
6/24/2021 10:59:22 AM | Reply
온라인포커 With these bets you predict that a total will be 4 to 10 (Small) or 11 to 17 (Big). Combination bets pay 2 to 1 and they are based on the value of two out of the three dice.
6/24/2021 10:59:01 AM | Reply
인터넷바카라 Sic Bo offers multiple betting options to choose from. However, you should know that some bets come with an extremely high house edge. The two bets with the most favourable odds are Small and Big that pay 1 to 1.
6/24/2021 10:58:42 AM | Reply
온라인바카라 When it comes to Craps, it uses two dice and a betting layout that can strike you as overwhelming. Just like in the game of Sic Bo, in Craps you should predict the outcome of each round by placing bets. A Craps round starts with a come-out roll which requires placing a Pass Line or the Don’t Pass Line bet.
6/24/2021 10:58:16 AM | Reply
온라인카지노 To win a prize, you have to predict value the dice show by placing bets. Although Sic Bo may seem complicated once you see the game’s betting layout, you will easily learn how to play it when you get to know the bets you can play.
6/24/2021 10:57:46 AM | Reply
더킹카지노 주소 Sic Bo is a dice game with its origins in Ancient China. While its name in Chinese means ‘dice pair’, the game is played with three dice shaken in a container.
6/24/2021 10:57:21 AM | Reply
한국 NO.1 온라인카지노 Stay with us to learn Sic Bo and Craps key features that can help you make your choice.
6/24/2021 10:56:52 AM | Reply
라이브바카라 Two casino games played with dice at live casinos are Sic Bo and Craps. If you have been wondering which one you should play, we got you covered.
6/24/2021 10:55:04 AM | Reply
ON THE INTERNET CASINOS ARE A EXCELLENT NIGHT TIME IN https://www.omgka.com
6/24/2021 9:58:16 AM | Reply
Page 1 of 6 FirstPrevious [1]2345 Last

Post a Comment

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive
Subscribe
Name

Text/HTML
Text/HTML
Contact Us
  • *
  • *