Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. Threading;
Using system. diagnostics;
Namespace _
{
Public partial class form1: Form
{
Public Delegate void del (string Str );
Public Delegate void del1 (string str1 );
Thread thread1, thread2;
Public form1 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
This. thread1 = new thread (New threadstart (this. SA ));
This. thread1.start ();
// MessageBox. Show (this ,);
This. button1.enabled = false;
// Obtain the current thread.
Int thread1id = thread. currentthread. gethashcode ();
String strthreadid = convert. tostring (thread1id );
MessageBox. Show (this, strthreadid );
}
Private void progressset (string text)
{
Progressbar1.value = 0;
Progressbar1.maximum = 999999;
For (INT I = 0; I <999999; I ++)
{
Progressbar1.value ++;
}
Progressbar1.value = 0;
}
private void SA ()
{< br> Del pro = new del (progressset);
This. invoke (Pro, new object [] {"hello"});
}
private void button2_click (Object sender, eventargs e)
{< br> This. thread2 = new thread (this. SA1);
thread2.start ();
This. button2.enabled = false;
// get the current thread
int thread2id = thread. currentthread. gethashcode ();
string strthreadid = convert. tostring (thread2id);
MessageBox. show (this, strthreadid);
}
private void SA1 ()
{< br> // Other Operations
// For example, set the textbox content on the Interface
del1 Mi1 = new del1 (updatetextbox );
This. invoke (Mi1, new object [] {"I Am a text box"});
}
// Method for updating the interface
private void updatetextbox (string Str)
{< br> // update
This. textbox1.text = STR;
}< BR >}