- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the Current Context id of the Thread in C#?
To create a new thread.
Thread thread = Thread.CurrentThread; thread.Name = "My new Thread”;
To get the current context id, use the ContextID property.
Thread.CurrentContext.ContextID
Let us see the complete code −
Example
using System; using System.Threading; namespace Demo { class MyClass { static void Main(string[] args) { Thread thread = Thread.CurrentThread; thread.Name = "My new Thread"; Console.WriteLine("Thread Name = {0}", thread.Name); Console.WriteLine("current Context id: {0}", Thread.CurrentContext.ContextID); Console.ReadKey(); } } }
Output
Thread Name = My new Thread current Context id: 0
Advertisements