
- 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
C# Program to pass Parameter to a Thread
To work with threads, add the following namespace in your code −
using System.Threading;
Firstly, you need to create a new thread in C# −
Thread thread = new Thread(threadDemo);
Above, threadDemo is our thread function.
Now pass a parameter to the thread −
thread.Start(str);
The parameter set above is −
String str = "Hello World!";
Example
Let us see the complete code to pass a parameter to a thread in C#.
using System; using System.Threading; namespace Sample { class Demo { static void Main(string[] args) { String str = "Hello World!"; // new thread Thread thread = new Thread(threadDemo); // passing parameter thread.Start(str); } static void threadDemo(object str) { Console.WriteLine("Value passed to the thread: "+str); } } }
Output
Value passed to the thread: Hello World!
- Related Articles
- How to pass a 2D array as a parameter in C?
- C# Program to Kill a Thread
- C# Program to Pause a Thread
- How to pass a function as a parameter in Java
- How can I pass a parameter to a setTimeout() callback?
- How to pass a json object as a parameter to a python function?
- C# Program to create a Simple Thread
- C# Program to Create a Thread Pool
- How to pass a jQuery event as a parameter in a method?
- How to pass an object as a parameter in JavaScript function?
- How to pass an array as a URL parameter in Laravel?
- Pass long parameter to an overloaded method in Java
- How to pass a lambda expression as a method parameter in Java?
- C++ Program to pass a string to the function
- How to pass import parameter values using SAP RFC class?

Advertisements