থ্রেডের সাথে কাজ করতে, আপনার কোডে নিম্নলিখিত নামস্থান যোগ করুন -
using System.Threading;
প্রথমত, আপনাকে C# −
-এ একটি নতুন থ্রেড তৈরি করতে হবেThread thread = new Thread(threadDemo);
উপরে, থ্রেডডেমো হল আমাদের থ্রেড ফাংশন।
এখন থ্রেড-
-এ একটি প্যারামিটার দিনthread.Start(str);
উপরে সেট করা প্যারামিটার হল −
String str = "Hello World!";
উদাহরণ
আসুন 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);
}
}
} আউটপুট
Value passed to the thread: Hello World!