从另一个线程调用Windows窗体(.NET) [英] Calling a windows form from another thread (.Net)

查看:183
本文介绍了从另一个线程调用Windows窗体(.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一个.NET应用程序,我想实现以下目标:

我有一个WinForms应用程序,和一个计时器(System.Timers.Timer的)是excecutes根据时间表线程。问题是,我无法从辅助线程(的WorkerThread)访问UI(windows窗体),错误说类似组件不能从一个线程访问了没有创造它。

有什么办法来实现这一目标?

谢谢!

解决方案

  formObject.Invoke(委托{
      //行动UI线程上执行
 });
 

Hi I'm developing a .Net application and I want to achieve the following:

I have a winforms application, and a timer (System.Timers.timer) that excecutes a thread based on a schedule. The problem is that I cannot access the UI (windows form) from the secondary thread (WorkerThread), the error say something like the component cannot be accessed from a thread that didn't create it.

Is there any way to achieve this?

Thanks!

解决方案

 formObject.Invoke(delegate { 
      // action to perform on UI thread
 });

这篇关于从另一个线程调用Windows窗体(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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