使用VB.Net将线程移动到主线程 [英] Move a Thread to Main Thread using VB.Net

查看:403
本文介绍了使用VB.Net将线程移动到主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个线程,该线程具有生成和显示新表格的功能.线程使用while true进行invinite循环.因此,我的表单始终只显示白色表单.我必须停止invinite循环才能使表格生效.

问题是,我不想停止invinite循环.我可以要求在我的线程中创建的表格移动到另一个线程吗?

感谢您的帮助.:)

I have a thread which has a function to Generate and Show a new Form. The thread do an invinite loop using while true. Because of that, my form always show up only white form. I must stop the invinite loop to make the form work.

The problem is, i don''t want to stop the invinite loop. Can i ask the form that created in my thread to move to the other thread??

Thanks for the help.. :)

推荐答案

您的表单应该在UI线程上创建,而不是在后台线程上创建.我将封送对方法的调用,该方法将创建表单返回给UI线程.
Your form should be created on the UI thread, not your background thread. I''d marshal a call to a method that creates the form back to the UI thread. This will keep your infinite loop going as well as eliminate the need for Sleep and DoEvents.


哇...那太好了....谢谢...
Wow... Thats work great.. thanksss...


在无限循环中插入Application.DoEventsThread.Sleep(...)


这篇关于使用VB.Net将线程移动到主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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