如何在wpf中工作Backgroundworker [英] How to work Backgroundworker in wpf

查看:565
本文介绍了如何在wpf中工作Backgroundworker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我对Backgroundworker有很大的问题,因为我想使用它但它不起作用我研究了它为什么它不起作用我发现它,它说你的后台工作者使用一个新的线程,这个线程不同于主要的UI线程,那次我试图使用名为Dispatcher.BeginInvoke的方法,但它仍然无法正常工作,请帮助我,我必须这样做,我不能。后台工作人员不是STA。

Hi guys, i have big problem about Backgroundworker, because i want to use it but it doesnt work i researched why it doesnt work and i found it ,it says your background worker uses a new thread, and this thread is different than the main UI thread ,that time i tried to use named Dispatcher.BeginInvoke method but it still doesnt work ,please help me ,i have to do it bu i couldnt. Background workers are not STA.

推荐答案

是的,我是如此soryy我在背景工作者Dowork中使用此代码

private void workerThread_DoWork(对象发送者) ,DoWorkEventArgs e)

{

Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background,new Action(委托){

ProgresBarWindow busy = new ProgresBarWindow( );

busy.Show();

}));

Dispatcher.Run();

}

但它仍然会出现关于Ui线程的错误
Yeah i am so soryy i use this code in Dowork of backgroundworker
private void workerThread_DoWork(object sender, DoWorkEventArgs e)
{
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new Action(delegate {
ProgresBarWindow busy = new ProgresBarWindow();
busy.Show();
}));
Dispatcher.Run();
}
but it still explodes error about Ui thread


这篇关于如何在wpf中工作Backgroundworker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆