Threading
-
Can anyone give mi code example of Threading using Thread.priority(),Thread.sleep(),Thread.CurrentThread,Thread.Start() Mini Thomas
-
Can anyone give mi code example of Threading using Thread.priority(),Thread.sleep(),Thread.CurrentThread,Thread.Start() Mini Thomas
hi, **Creating Threads :**Create new instance of Thread object. Thread constructor accepts one parameters which is delegate Thread dummyThread = new Thread( new ThreadStart(dummyFunction) ); Executing Thread: To run this thread us the method start provided by Threading namespace DummyThread.Start (); Joining Threads: There is always the requirement to join thread specially when a thread depends on some other thread for completing its task. Lets assume that DummyThread has to wait for DummyPriorityThread to complete its task and then run again. In this case we need to do the following: DummyPriorityThread.Join() ; Suspending Thread: This will suspend the thread for the given number of seconds DummyPriorityThread.Sleep(); **Killing Thread:**When there is a need to kill a thread use the following to achieve the same. DummyPriorityThread.Abort(); hope this will give u some idea... thanks, Suketh
-
hi, **Creating Threads :**Create new instance of Thread object. Thread constructor accepts one parameters which is delegate Thread dummyThread = new Thread( new ThreadStart(dummyFunction) ); Executing Thread: To run this thread us the method start provided by Threading namespace DummyThread.Start (); Joining Threads: There is always the requirement to join thread specially when a thread depends on some other thread for completing its task. Lets assume that DummyThread has to wait for DummyPriorityThread to complete its task and then run again. In this case we need to do the following: DummyPriorityThread.Join() ; Suspending Thread: This will suspend the thread for the given number of seconds DummyPriorityThread.Sleep(); **Killing Thread:**When there is a need to kill a thread use the following to achieve the same. DummyPriorityThread.Abort(); hope this will give u some idea... thanks, Suketh
protected void Page_Load(object sender, EventArgs e) { Thread pthread1 = new Thread(new ThreadStart(Thread1)); Thread pthread2 = new Thread(new ThreadStart(Thread2)); pthread1.Start(); } public void Thread1() { string strThread1; strThread1 = "I am first thread."; for (int i=0;i<5;i++ ) { ListBox1.Items.Add(strThread1); if(i==3) { pthread2.Join(); } } } public void Thread2() { string strThread2; strThread2 = "I am second thread."; for (int j=0;j<5;j++) { ListBox1.Items.Add(strThread2); } } I want to call pthread2.Join() in public void Thread1() but gives error also i need to access pthread1 in public void Thread2()..How to do this? Mini Thomas