一种方法访问两个线程 [英] Accessing Two Threads in One Method

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

问题描述



我有两个类想要访问一个方法,即class2中的class1(带有委托),但是在运行时会发生此异常:

Hi

I have two classes that want access one method, class1 in class2 (with delegates) but when run, this exception occurred:

System.InvalidOperationException (The calling thread cannot access this object because a different thread owns it.) 


评论:
我有两个类别,一个类别访问图形层,第二个类别是计算层,但是我想在计算以并行方式运行时显示我想要的图形
访问class1中执行此工作的一个方法.和class2创建class1"

是否可以使用其他方法?如果可以,怎么办?

谢谢.


Comments:
"I have two class one class access graphical layer and second class is Calculation layer, but i want when calculation is running as parallel show graphical that i want
access one method in class1 that do this work. and class2 create class1 "

Is it possible to access another method? If so, how?

Thanks.

推荐答案

看起来像您正在使用WPF吗?您是否尝试过 BackgroundWorker [
Looks like you are using WPF ? Have you tried BackgroundWorker[^] ? It reports progress on UI thread. Or read about Dispatcher.Invoke (WPF/WinForms)


这篇关于一种方法访问两个线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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