O'Reilly logo

C# 2008 and 2005 Threaded Programming: Beginner's Guide by Gastón C. Hillar

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

Time for action - Identifying threads and giving them names

Now, we are going to make some changes to the code in order to identify the threads. We are going to give them names:

  1. Stay in the project, MarsEncrypter.
  2. Open the code for the Windows Form Form1 (frmMarsEncrypter).
  3. Open the Form Load event and add the following code; we want to identify the UI thread:
    // Give a name to identify the thread that creates the UI
    Thread.CurrentThread.Name = "UI Thread";
    
  4. Add the following line of code in the ThreadProc method, before the line, loEncrypter.EncryptFile();. We want to identify each thread created by the ThreadPool:
    // Give the thread a name
    Thread.CurrentThread.Name = "ThreadPool: " + loEncrypter. psInputFileName;
    

What just happened?

Now, each thread ...

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