O'Reilly logo

Visual Studio 2013 and .NET 4.5 Expert Cookbook by Abhishek Sur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Debugging a multithreaded program

Multithreaded programming is one of the primary needs in modern day programming. In this recipe, let's take a look at how to debug a multithreaded program.

Getting ready

To test a multithreaded program, let's consider the following code:

static void Main()
{
  Thread.CurrentThread.Name = "Main Thread";
  Thread t1 = new Thread(new ThreadStart(Run));
  t1.Name = "Thread 1";
  Thread t2 = new Thread(new ThreadStart(Run));
  t2.Name = "Thread 2";
  t1.Start();
  t2.Start();
  Run();
}
static void Run()
{
  Console.WriteLine("hello {0}!", Thread.CurrentThread.Name);
  Thread.Sleep(1000);
}

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required