๐Thread
using System.Threading;
class Program
{
static Thread thread1, thread2;
public static void Main()
{
thread1 = new Thread(ThreadProc);
thread1.Name = "Thread1";
thread1.Start();
thread2 = new Thread(ThreadProc);
thread2.Name = "Thread2";
thread2.Start();
}
private static void ThreadProc()
{
Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
if (Thread.CurrentThread.Name == "Thread1" &&
thread2.ThreadState != ThreadState.Unstarted)
{
Console.WriteLine("๋๋ {0} thread2๊ฐ ๋๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฝ๋๋ค.", Thread.CurrentThread.Name);
thread2.Join(); // ํ์ฌ ์ค๋ ๋ thread1์ด ์งํ์ค์ ๋จ์ ์ค๋ ๋(thread2)๋ฅผ join()์์ผ์ waitํ๋์ค.
Console.WriteLine("๋๋ {0} thread2๊ฐ ๋๋์ ์ด์ด ์งํํฉ๋๋ค..", Thread.CurrentThread.Name);
}
Console.WriteLine("๋๋ {0} Sleep(4000) ๋ค์ด๊ฐ๋๋ค.",Thread.CurrentThread.Name);
Thread.Sleep(4000);
Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
Console.WriteLine("Thread1: {0}", thread1.ThreadState);
Console.WriteLine("Thread2: {0}\n", thread2.ThreadState);
}
}
with Parameter
class Param1
{
public string aa { get; set; }
public Action<string, int> callback { get; set; }
public int annon { get; set; }
public HttpWebRequest request { get; set; }
}
{
Param1 param1 = new Param1
{
aa = aa,
callback = callback,
annon = annon,
request = request
};
Thread t1 = new Thread(new ParameterizedThreadStart(Func1));
t1.Start(param1);
}
public static void Func1(object param)
{
// ...
}
Last updated