GUI线程 [英] GUI thread

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

问题描述



我有很大的问题。我制作了可以渲染的通用形式,并且作为该动作的结果,我获得了System.Windows.Forms.Form对象。

渲染必须在GUI中完成线程(一个有消息泵),但是我不能保证在GUI线程中使用Render函数。

这是渲染函数:


公共对象渲染(Synchronizer.T sync)

{

return sync.Render(this); < - 这个函数正在制作真正的表格

}


我想要Render函数在GUI线程中总是这么做。任何人都可以帮助我吗?

Thanx,Cheya

Hi,
I have big problem. I made generic form which can be rendered, and as a
result of that action, I get System.Windows.Forms.Form object.
Rendering must be done in GUI thread (one which has message pump), but I
can''t garantee that the using of Render function will be made in GUI thread.
This is Render function:

public object Render(Synchronizer.T sync)
{
return sync.Render(this); <-- this function is making real Form
}

I want that Render function is doing in GUI thread allways. Can anyone
help me?
Thanx, Cheya

推荐答案

Hello Cheya,


您应该查看InvokeRequired属性。
http://msdn.microsoft.com/library/de...uiredtopic.asp


基本示例:

<伪代码>

public delegate void TestMeDelegate();

public void TestMe ()

{

if(!this.InvokeRequired)

{

//根据需要更新ui元素...

}

其他

{

TestMeDelegate委托=新的TestMeDelegate();

this.BeginInvoke(delegate);

}

}

< / pseudo-code>


此外,这是一篇关于多线程WinForms应用程序的精彩文章。
http://msdn.microsoft.com/library /de...ms06112002.asp

HTH,


Kyril


" Nenad Dobrilovic" < CH ******* @ hotmail.com>在消息中写道

news:u5 ************** @ TK2MSFTNGP10.phx.gbl ...
Hello Cheya,

You should look into the InvokeRequired property.
http://msdn.microsoft.com/library/de...uiredtopic.asp

A basic example:
<pseudo-code>
public delegate void TestMeDelegate();
public void TestMe()
{
if(!this.InvokeRequired)
{
//update ui elements as needed...
}
else
{
TestMeDelegate delegate = new TestMeDelegate();
this.BeginInvoke(delegate);
}
}
</pseudo-code>

Also, here is a great article on Multi-threading WinForms apps.
http://msdn.microsoft.com/library/de...ms06112002.asp
HTH,

Kyril

"Nenad Dobrilovic" <ch*******@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
我有很大的问题。我创建了可以呈现的通用表单,并且作为该操作的结果,我获得了System.Windows.Forms.Form对象。
渲染必须在GUI线程中完成(一个有消息泵的线程) ,但我不能保证渲染功能的使用将在GUI
线程中进行。
这是渲染功能:

公共对象渲染( Synchronizer.T sync)
{return sync.Render(this); < - 这个函数正在制作真实的表格

我希望Render函数在GUI线程中一直在做。任何人都可以帮助我吗?
Thanx,Cheya
Hi,
I have big problem. I made generic form which can be rendered, and as a
result of that action, I get System.Windows.Forms.Form object.
Rendering must be done in GUI thread (one which has message pump), but I
can''t garantee that the using of Render function will be made in GUI
thread.
This is Render function:

public object Render(Synchronizer.T sync)
{ return sync.Render(this); <-- this function is making real Form
}

I want that Render function is doing in GUI thread allways. Can anyone
help me?
Thanx, Cheya



Kyril Magnos写道:
Kyril Magnos wrote:
你好Cheya,

你应该查看InvokeRequired属性。
http://msdn.microsoft.com/library/de...uiredtopic.asp

一个基本的例子:
<伪代码>
公共委托void TestMeDelegate();
public void TestMe()
{
if(! this.InvokeRequired)
//
//根据需要更新ui元素......

其他
{
TestMeDelegate delegate = new TestMeDelegate();
this.BeginInvoke(delegate);
}
}
< / pseudo-code>

此外,这是一篇很棒的文章线程化WinForms应用程序。
http://msdn.microsoft.com/library/de .. .ms06112002.asp

HTH,

Kyril

Nenad Dobrilovic < CH ******* @ hotmail.com>在消息中写道
新闻:u5 ************** @ TK2MSFTNGP10.phx.gbl ...
Hello Cheya,

You should look into the InvokeRequired property.
http://msdn.microsoft.com/library/de...uiredtopic.asp

A basic example:
<pseudo-code>
public delegate void TestMeDelegate();
public void TestMe()
{
if(!this.InvokeRequired)
{
//update ui elements as needed...
}
else
{
TestMeDelegate delegate = new TestMeDelegate();
this.BeginInvoke(delegate);
}
}
</pseudo-code>

Also, here is a great article on Multi-threading WinForms apps.
http://msdn.microsoft.com/library/de...ms06112002.asp
HTH,

Kyril

"Nenad Dobrilovic" <ch*******@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
我有很大的问题。我创建了可以呈现的通用表单,并且作为该操作的结果,我获得了System.Windows.Forms.Form对象。
渲染必须在GUI线程中完成(一个有消息泵的线程) ,但我不能保证渲染功能的使用将在GUI
线程中进行。
这是渲染功能:

公共对象渲染( Synchronizer.T sync)
{return sync.Render(this); < - 这个函数正在制作真实的表格

我希望Render函数在GUI线程中一直在做。任何人都可以帮助我吗?
Thanx,Cheya
Hi,
I have big problem. I made generic form which can be rendered, and as a
result of that action, I get System.Windows.Forms.Form object.
Rendering must be done in GUI thread (one which has message pump), but I
can''t garantee that the using of Render function will be made in GUI
thread.
This is Render function:

public object Render(Synchronizer.T sync)
{ return sync.Render(this); <-- this function is making real Form
}

I want that Render function is doing in GUI thread allways. Can anyone
help me?
Thanx, Cheya





问题是InvokeRequired属性,Invoke()方法等是在System.Windows.Forms.Control类中定义的


但是,我的类是通用形式(它不是继承自

System.Windows.Forms.Control),可以使用Render()

方法和Synchronize对象''渲染'。

我想告诉GUI线程''对我这样做'来自我的对象。



The problem is that InvokeRequired property, Invoke() method, etc. is
defined in System.Windows.Forms.Control class.
But, my class is generic form (it is not inherited from
System.Windows.Forms.Control), which can be ''rendered'' using Render()
method and Synchronize object.
I want to tell GUI thread ''do this to me'' from my object.


Nenad Dobrilovic< ch ******* @ hotmail.com>写道:
Nenad Dobrilovic <ch*******@hotmail.com> wrote:
问题是在System.Windows.Forms.Control类中定义了InvokeRequired属性,Invoke()方法等。
但是,我的类是通用的form(它不是继承自System.Windows.Forms.Control),可以使用Render()
方法和Synchronize对象''渲染'。
我想告诉GUI线程''对我这样做'来自我的对象。
The problem is that InvokeRequired property, Invoke() method, etc. is
defined in System.Windows.Forms.Control class.
But, my class is generic form (it is not inherited from
System.Windows.Forms.Control), which can be ''rendered'' using Render()
method and Synchronize object.
I want to tell GUI thread ''do this to me'' from my object.




然后你需要知道* a *控件(任何控件)在

该线程。请记住,事实上可以有几个GUI线程

- 但是很多你称之为Application.Run,​​基本上。 (或者多少

你创建控件,取决于你对事物的看法。)


-

Jon Skeet - < sk *** @ pobox.com>
http:// www。 pobox.com/~skeet

如果回复小组,请不要给我发邮件



Then you''ll need to know *a* control (any control) which is running on
that thread. Bear in mind that there can in fact be several GUI threads
- however many you call Application.Run on, basically. (Or however many
you create controls in, depending on your view of things.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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