Improve company productivity with a Business Account.Sign Up


Thread Example

Posted on 2006-11-25
Medium Priority
Last Modified: 2010-04-16

How to use thread in the C#,

Can someone give me small example on threads

Kind Regards,
Question by:dinesh_bali
  • 5
LVL 20

Expert Comment

ID: 18011260
public System.Threading.Thread Thread1 = new Thread(new ThreadStart(AlertIt_One));
public System.Threading.Thread Thread2 = new Thread(new ThreadStart(AlertIt_Two));

public void Button1_Click(object sender, EventArgs e)

public void AlertIt_One()
MessageBox("Fired 1");

public void AlertIt_Two()
MessageBox("Fired 2");

Author Comment

ID: 18011283
Hi Thanks for the example.

Can we commumicate between two threads

say thread 1 and thread 2, when the process of the thread 1 completes

Kind Regards
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

LVL 29

Expert Comment

ID: 18011316
Yes - you can raise events between the threads.

Or you can simply have a timer in the main thread checking the state of the thread:
if (
Thread1.ThreadState == ThreadState.Unstarted ||
Thread1.ThreadState == ThreadState.Stopped ||
Thread1.ThreadState == ThreadState.Aborted ||
Thread1.ThreadState == ThreadState.Suspended )
  This thread is dead.

Have a look at for some more examples
LVL 29

Expert Comment

ID: 18011399
Sorry, I am working in too many languages at the same time - they are all starting to merge into one ;). That was a VB.NET example

have a look at 'Using events for thread synchronization'
LVL 29

Accepted Solution

Nightman earned 2000 total points
ID: 18011411
Another example:

Both this one and my previous post have downloadable, working code samples
LVL 29

Expert Comment

ID: 18198051
Hi dinesh_bali

Did our comments assist you? If not, please can you provide some feedback so that we can assist you further. Alternatively, have a look at for information on closing questions.


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Watch the video to know the process of migration of Exchange or Office 365 mailboxes in absence of MS Outlook. It is an eminent tool which can easily migrate Public, Archive user mailboxes from one another Exchange server and Office 365. Kernel Migr…
Watch the software video of Kernel Import PST to Office 365 tools which can easily import PST and OST files to Office 365 for bulk mailboxes. The process of migration is simple and user can map source and destination mailboxes and easily import data…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question