Windows窗体在单独的线程中 [英] Windows Form in seperate thread

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

问题描述

大家好,

想知道这个问题是用什么方法的。


我有一个MDIApplication,MDIClinets应该是一个单独的线程。

所以我做过这样的事情,


//创建一个新的Show方法来启动一个新的线程

public new void Show()

{

Thread t = new Thread(new ThreadStart(ThreadProc));

t.Start();

}

public void ThreadProc()

{

base.Show();

}


现在我的问题是我基本上没有运行循环,所以只要

表单显示线程退出我几乎留在了汤里。


我确定其他人在.NET中这样做了吗?

任何想法建议等?


感谢您的时间

Brian Keating。

解决方案

On 2004-11-25,Brian Keating EI9FXB<>写道:

大家好,
想知道这个问题是用什么方法的。

我有一个MDIApplication,MDIClinets应该是一个单独的线程。
所以我做了类似的事情,

//创建一个新的Show方法来启动一个新的线程
public new void Show()
{
线程t =新线程(新的ThreadStart(ThreadProc));
t.Start();
}

public void ThreadProc()
{
base.Show();
}
现在我的问题是我基本上没有运行循环,所以只要
表单显示主题退出,我几乎留在汤里。

我确定其他人在.NET中做过这个吗?
任何想法建议等?

谢谢您的时间
Brian Keating。




在新主题中调用Application.Run ...


private void ThreadProc()

{

Application.Run(new Form());

}


-

汤姆谢尔顿[MVP]


嗨汤姆


如何使用你应该有一个用户界面线程每个

应用程序规则 - 我们是否为这个方法为每个MDI儿童

窗口提供单独的消息泵?


真的很感兴趣...


Nigel Armstrong


" Tom Shelton"写道:

2004-11-25,Brian Keating EI9FXB<>写道:

大家好,
想知道这个问题是用什么方法的。

我有一个MDIApplication,MDIClinets应该是一个单独的线程。
所以我做了类似的事情,

//创建一个新的Show方法来启动一个新的线程
public new void Show()
{
线程t =新线程(新的ThreadStart(ThreadProc));
t.Start();
}

public void ThreadProc()
{
base.Show();
}
现在我的问题是我基本上没有运行循环,所以只要
表单显示主题退出,我几乎留在汤里。

我确定其他人在.NET中做过这个吗?
任何想法建议等?
Brian Keating。



在新主题中调用Application.Run ...

private void ThreadProc()
{
Application.Run(新表格());
}

- 汤希lton [MVP]



准确的规则说明


你不能从一个UI元素访问创建它的线程以外的线程


Internet Explorer有多个UI线程 - 每个IE窗口都在自己的UI线程中运行,即使只有一个进程。


问候


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk


嗨汤姆


这是如何工作的你应该有一个用户界面线程每个

应用程序规则 - 我们是否为这个方法为每个MDI儿童

窗口提供单独的消息泵?


真的很感兴趣...

Hello all,
Wonder what approach is used for this problem.

I have a MDIApplication, the MDIClinets are to be in a seperate thread.
So I''ve done something like this,

// Create a new Show method that starts a new thread
public new void Show()
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
public void ThreadProc()
{
base.Show();
}

Now my problem is that I basically don''t have a run loop, so as soon as the
Form shows the thread exits and I''m pretty much left in the soup.

I''m sure other people have done this in .NET?
Any ideas suggestions etc?

Thanks for you time
Brian Keating.

解决方案

On 2004-11-25, Brian Keating EI9FXB <> wrote:

Hello all,
Wonder what approach is used for this problem.

I have a MDIApplication, the MDIClinets are to be in a seperate thread.
So I''ve done something like this,

// Create a new Show method that starts a new thread
public new void Show()
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
public void ThreadProc()
{
base.Show();
}

Now my problem is that I basically don''t have a run loop, so as soon as the
Form shows the thread exits and I''m pretty much left in the soup.

I''m sure other people have done this in .NET?
Any ideas suggestions etc?

Thanks for you time
Brian Keating.



Call Application.Run in the new thread...

private void ThreadProc ()
{
Application.Run (new Form ());
}

--
Tom Shelton [MVP]


Hi Tom

How does this work with the "Thou Shalt have one User Interface thread per
application" rule - do we get a separate message pump for each MDI Child
window with this approach?

Just interested really...

Nigel Armstrong

"Tom Shelton" wrote:

On 2004-11-25, Brian Keating EI9FXB <> wrote:

Hello all,
Wonder what approach is used for this problem.

I have a MDIApplication, the MDIClinets are to be in a seperate thread.
So I''ve done something like this,

// Create a new Show method that starts a new thread
public new void Show()
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
public void ThreadProc()
{
base.Show();
}

Now my problem is that I basically don''t have a run loop, so as soon as the
Form shows the thread exits and I''m pretty much left in the soup.

I''m sure other people have done this in .NET?
Any ideas suggestions etc?

Thanks for you time
Brian Keating.



Call Application.Run in the new thread...

private void ThreadProc ()
{
Application.Run (new Form ());
}

--
Tom Shelton [MVP]



The precise rule states

"Thou shalt not access a UI element from a thread other than the thread that created it"

Internet Explorer has multiple UI threads for example - each IE windows runs in its own UI thread even though there is noly one process.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi Tom

How does this work with the "Thou Shalt have one User Interface thread per
application" rule - do we get a separate message pump for each MDI Child
window with this approach?

Just interested really...


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

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