我有一個程序,我用C#寫了一個窗口。我有一個按鈕,做一些事情(它並不重要),並刷新他的循環中的窗口(在button_click功能)(與this.Invalidate(假);(我不使用這個。刷新,因爲我有一個組框,我不想刷新))。如何將參數傳遞給我的線程?
當button_click函數工作時,窗口「卡住」,我不能最小化窗口。
我正試圖在不同的線程中使用此按鈕的代碼,但它有處理來自主窗體的參數的xome問題。 可以說我有這樣的代碼:
void button_click(object sender, EventArgs e)
{
/*want to put this in new thread*/
progressBar1.Value = 0;
progressBar1.Maximum = int.Parse(somelabel_num.Text);
int i;
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
if (file.FileName == "")
return;
Bitmap image = new Bitmap(file.FileName);
groupBox1.BackgroundImage = image;
for (i = 0; i < int.Parse(somelabel_num.Text); i++)
{
somelabel.Text = i;
this/*(main form)*/.Invalidate(false);
progressBar1.PerformStep();
}
/*want that here the new thread will end*/
}
所以如何做到這一點作爲獲取paremeters(progressBar1,groupBox1和somelabel)線程?
線程共享內存空間。你有什麼問題?是產卵線程的代碼? – Rig
請看我的編輯問題(我用兩個「/ ** /」編輯代碼(butten_click函數在MainForm中(項目的主窗體(一個Windows項目),並且沒有其他線程) – George