থ্রেড নিয়ে কাজ করতে নেমস্পেস যোগ করুন:
using System.Threading;
প্রথমে একটি নতুন থ্রেড তৈরি করুন:
Thread thread = new Thread(threadDemo);
এখানে threadDemo হলো আমাদের থ্রেড ফাংশন।
এখন থ্রেডে প্যারামিটার পাস করুন:
thread.Start(str);
প্যারামিটারটি হলো:
String str = "Hello World!";
সম্পূর্ণ উদাহরণ
using System;
using System.Threading;
namespace Sample {
class Demo {
static void Main(string[] args) {
String str = "Hello World!";
// নতুন থ্রেড
Thread thread = new Thread(threadDemo);
// প্যারামিটার পাস করা
thread.Start(str);
}
static void threadDemo(object str) {
Console.WriteLine("Value passed to the thread: " + str);
}
}
}
আউটপুট
Value passed to the thread: Hello World!