我是 WPF(以及一般计算机科学)的新手,我的老板给了我一个小项目,其中有 5 个选项卡,每个选项卡都转到不同的站点。登录后,用户被定向到第一个选项卡的网站。在后台,其他 4 个选项卡应该在后台加载。
每个都有以下名称:“tabItem1”、“tabItem2”、“tabItem3”、“tabItem4”到“tabItem5” 每个内部都有一个最多“webBrowser5”。
我认为我必须使用线程在后台加载页面,但我不确定如何实现它。我尝试在 MainWindow 中创建 4 个不同的线程,例如:
public MainWindow()
{
InitializeComponent();
Thread thread1 = new Thread(Update1);
thread1.SetApartmentState(ApartmentState.STA);
thread1.Start();
Thread thread2 = new Thread(Update2);
thread2.SetApartmentState(ApartmentState.STA);
thread2.Start();
Thread thread3 = new Thread(Update3);
thread3.SetApartmentState(ApartmentState.STA);
thread3.Start();
Thread thread4 = new Thread(Update4);
thread4.SetApartmentState(ApartmentState.STA);
thread4.Start();
}
private void Update1()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(ThreadStart)delegate()
{
tabItem2.Focus();
}
);
}
private void Update2()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(ThreadStart)delegate()
{
tabItem3.Focus();
}
);
}
//...Goes up to Update4
这似乎只关注最后一个线程,也没有在后台进行。我感谢任何指导和帮助。谢谢!