0 c#
每当我设置选定的选项卡
tcTabs.SelectedTab = secondTab;
Run Code Online (Sandbox Code Playgroud)
整个应用程序冻结,没有任何错误消息.我怎样才能解决这个问题?
一些代码
private void downloadThread()
{
WebClient wc;
wc = new WebClient();
lbStatus.Text = "Creating directory";
System.IO.Directory.CreateDirectory("C:\\Program Files\\foo");
pbMain.Value = 33;
Thread.Sleep(1000);
lbStatus.Text = "Downloading files";
wc.DownloadFile("http://website.net/foo.exe", "C:\\Program Files\\foo\\foo.exe");
Thread.Sleep(1000);
pbMain.Value = 66;
lbStatus.Text = "Creating shortcuts";
appShortcutToDesktop("C:\\Program Files\\foo\\foo.exe", "foo");
pbMain.Value = 100;
Thread.Sleep(1000);
tcMain.Width = 186;
tcMain.Height = 122;
this.Width = 186;
this.Height = 122;
tcMain.SelectedTab = tpName;
while (tcMain.SelectedTab != tpAddWebsites)
Thread.Sleep(1000);
tcMain.Width = 218;
tcMain.Height = 147;
this.Width = 218;
this.Height = 147;
}
Run Code Online (Sandbox Code Playgroud)
selectedtab设置为tpName后的应用程序图片 http://segnosis.net/screenshots/b1ktn5.png
如果要在线程中切换选项卡,则需要使用Form.Invoke:
void SetSecondTab()
{
tcTabs.SelectedTab = secondTab;
}
void SwitchTabsFromThread()
{
this.Invoke(new Action(() => { SetSecondTab(); }));
}
Run Code Online (Sandbox Code Playgroud)