Click here to Skip to main content
12,816,406 members (34,144 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 28 Jul 2012

Switching between filtered threads

, 28 Jul 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
About switching between filtered threads


Threads dropdown in Debug Location Toolbar provide a quick way of switching between various threads and observe details about what lines of code are currently been executed by those threads. If you don’t know which control I am referring to, the figure below shows threads dropdown in debug location toolbar.

In case you don’t see this dropdown in your Visual Studio toolbar, make sure that you have Debug Locations toolbar checked in the toolbar context menu as shown below:

If your application has many threads and you need to focus on few threads at a given time, then finding those threads out of a long list and switching between these could become a bit cumbersome. Let’s take a look at the code to describe what exactly I am talking about.

static void Main(string[] args)
    Thread[] workers = new Thread[25];
    for (int i = 0; i < workers.Length; i++)
        if (i > 0 && i % 21 == 0)
            workers[i] = new Thread(new ThreadStart(Method1));
        else if (i > 0 && i % 23 == 0)
            workers[i] = new Thread(new ThreadStart(Method2));
            workers[i] = new Thread(new ThreadStart(Method3));
        workers[i].Name = "Thread" + i.ToString();
    Console.WriteLine("Thread Creation Completed.");

    for (int i = 0; i < workers.Length; i++)


private static void Method1()

private static void Method2()

private static void Method3()

In this code, we have instantiated twenty-five threads. Out of these, one thread will be executing Method1, another one will be executing Method2 while other twenty-three threads will be executing Method3. Let’s run this code in debug mode, and put a breakpoint on the following line of code:

Console.WriteLine("Thread Creation Completed.");

Let’s assume that there is some issue that you need to debug and it requires to switch between threads that involves Method1 and Method2. At this point, if you inspect the Threads dropdown in Debug Location toolbar, you will see that all twenty-five threads are listed here and switching between those two threads require to scroll the window, find right threads, etc. To keep doing this could be quite cumbersome.

In order to simplify this switching between threads involving Method1 and Method2 only, you can go in Threads window and select the flag in the left most columns for threads that are executing Method1 and Method2.

Once you flag threads of your interest, you click on "Show Only Flagged Threads" button in the toolbar as shown below:

Once this button is enabled, you will only see the flagged threads in the Threads window as shown below:

Hopefully you will find this tip helpful.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kamran Bilgrami
Canada Canada
Kamran Bilgrami is a seasoned software developer with background in designing mission critical applications for carrier grade telecom networks. More recently he is involved in design & development of real-time biometric based security solutions. His areas of interest include .NET, software security, mathematical modeling and patterns.

He blogs regularly at

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 29 Jul 2012
Article Copyright 2012 by Kamran Bilgrami
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid