
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How to get current thread id in android?
- How to get the thread ID from a thread in C#?
- How to display the name of the Current Thread in C#?
- How to obtain Status of the Current Thread in C#?
- Fetching the name of the current thread in Java
- How to get getAllStackTraces of current thread in android?
- How to display all stack frames of the current thread in Java 9?
- How to get current foreground activity context in Android?
- How to get current thread count in android?
- How to get current thread name in android?
- How to get current thread priority in android?
- How to get current thread state in android?
- How to check current state of a thread in C#?
- How to get current thread is daemon in android?
- How to get current thread is interrupted in android?

Advertisements