কম্পিউটার টিউটোরিয়াল

C#-এ থ্রেডে প্যারামিটার পাস করা


থ্রেড নিয়ে কাজ করতে নেমস্পেস যোগ করুন:

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!
  1. C#-এ করেন্ট থ্রেডের প্রায়োরিটি দেখানো

  2. C#-এ কারেন্ট থ্রেডের নাম দেখানো

  3. C#-এ ক্যারেক্টার কেস রূপান্তর (Upper/Lower)

  4. C#-এ কারেন্ট থ্রেডের স্ট্যাটাস চেক করা (IsAlive)