VB .NET跨线程挑战 [英] VB .NET cross-threading challenge

查看:77
本文介绍了VB .NET跨线程挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方.NET库,它使用后台工作程序监视外围设备。我已经添加了一个处理程序来捕获引发的事件,但是当我尝试更新UI时,我收到一个异常,因为我的UI调用是来自后台工作程序而不是UI线程的引发事件线程。第三方库声明应该使用ControlBeginInvoke调用UI事件,但我没有运气试图让它工作。该计划应该非常简单;所以,如果可能的话,我想避免大量的管道工程。这就是我到目前为止所拥有的。我没有包括我调用UI线程的所有尝试。

I''m using a 3rd party .NET library which monitors a peripheral with a backgroundworker. I''ve added a handler to catch a raised event, but when I try to update the UI I receive an exception because my UI call is on the raised event thread from the background worker and not the UI thread. The 3rd party library states that UI events should be called with ControlBeginInvoke, but I''ve had no luck trying to get it to work. The program is supposed to be very simply; so, I''d like to avoid a lot of plumbing if possible. Here''s what I have so far. I''m not including all of my attempts to call the UI thread.

展开 | 选择 | Wrap | 行号

推荐答案

I前一段时间有类似的问题。

和我的非主线程正在寻找用户界面


我使用了control.InvokeRequired for this

我基本上是用户界面这是真的。


它对我有用。但由于某种原因,我认为我从我的申请中删除了线程。


祝你好运
I had a similar issue sometime ago.
and my non main thread was chaging the UI

I used the control.InvokeRequired for this
I basically chnaged the UI is this was true.

It worked for me. But for some reason i think i took the threading off my application.

good luck



我前段时间遇到过类似的问题。

和我的非主要线程正在寻找用户界面


我使用了control.InvokeRequired for this

我基本上是用户界面这是真的。


它对我有用。但由于某些原因,我认为我从我的申请中删除了线程。


祝你好运
I had a similar issue sometime ago.
and my non main thread was chaging the UI

I used the control.InvokeRequired for this
I basically chnaged the UI is this was true.

It worked for me. But for some reason i think i took the threading off my application.

good luck



嗯...... InvokeRequired确认需要调用。所以,在我最初的帖子中,我说我需要调用Invoke或BeginInvoke,但我似乎无法让它正常工作。最初发布的代码是我的,它调用第三方.NET库。该库有一个(静态)单例,当设置为true时,初始化第三方库中的后台工作线程。我无法直接控制黑匣子,所以除了弄清楚如何让跨线程函数调用响应从黑盒子引发的事件以外,我真的没有明确的选择。我无法从应用程序中删除线程。

Hmmm... InvokeRequired confirms that an Invoke is required. So, in my initial post I stated that I need to call Invoke or BeginInvoke, but I can''t seem to get it to work properly. The code initially posted is mine, and it calls the 3rd party .NET library. This library has a (static) singleton which, when set to true, initializes a backgroundworker thread in the 3rd party library. I have no direct control over the "Black Box," and so I really have no clear alternative other than to figure out how to get the cross-thread function call to work in response to an event raised from the "Black Box." I can''t remove threading from the app.


如果你的第三方代码控制控件的属性(基于UI),你不能做任何事情,那么我认为你应该请他们支持这个问题!
If your 3rd party code is controlling the properties of the controls (UI based) and you cannot to anything to that, then i think you should ask them for support for this issue!


这篇关于VB .NET跨线程挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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