的BackgroundWorker [英] BackGroundWorker

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

问题描述

我有一个应用程序在启动时创建一个非常密集的TreeView

时间。我让程序在单个线程上成功运行,但是

的启动时间有点过分了。当应用程序启动时,用户登录是一个

的要求,所以在我的神奇智慧中,我想在另一个线程上推动所有这些处理,所以它用户登录时加载。我的b $ b已经在线程上运行了所有代码OK,但我无法弄清楚如何将
返回数据到主线程以便我可以更新UI main

线程。


在BackgroundWorker任务中,我创建了一个新的TreeView,它不是附加到任何UI的
。我在后台构建了这个,然后尝试通过MSMQ队列传递

,但不幸的是,TreeView类在非


有人可以解释一下将这些数据返回主要的最佳方式

帖子。


谢谢提前


杰米

I have an application that creates a pretty intensive TreeView at startup
time. I had the program running on a single thread sucessfully, but the
startup time was a bit excessive. When the application starts up it is a
requirement for the user to log on, so in my magical wisdom, I thought shove
all this processing on another thread, so it loads while the user logs on. I
have all the code running on the thread OK, but I cannot figure out how to
return the data to the main thread so that I can update the UI from the main
thread.

In the BackgroundWorker task I have created a new TreeView that is not
attached to any UI. I build this in the background, I then attempted to Pass
this back through an MSMQ Queue, but unfortunately the TreeView class in non
Serializable so the Queue.Send fails.

Can someone please explain to the best way to return this data to the main
thread.

Thanks in advance

Jamie

推荐答案

恕我直言,这样的事情更容易,也是一个直截了当的模式: br /> http://channel9.msdn.com/ShowPost.aspx ?PostID = 171594


-

William Stacey [MVP]


" Jamie的Bissett" < JA ********** @ yahoo.com>在消息中写道

新闻:uU ************** @ TK2MSFTNGP02.phx.gbl ...

|我有一个申请在启动时创建一个非常密集的TreeView

|时间。我让程序成功运行在单个线程上,但是

|启动时间有点过分。当应用程序启动时,它是一个

|要求用户登录,所以在我的神奇智慧中,我认为

推了

|所有这些处理都在另一个线程上,所以它会在用户登录时加载。



|让所有代码在线程上运行OK,但我无法弄清楚如何使用
|将数据返回到主线程,以便我可以从

main更新UI

|线程。

|

|在BackgroundWorker任务中,我创建了一个不是
|的新TreeView附加到任何UI。我在后台构建了这个,然后尝试了

Pass

|这可以通过一个MSMQ队列返回,但不幸的是,这个TreeView类在



|可序列化,因此Queue.Send失败。

|

|有人可以解释一下将这些数据返回主要的最佳方式

|线程。

|

|在此先感谢

|

| Jamie

|

|
IMHO, something like this is easier and a straight forward pattern:
http://channel9.msdn.com/ShowPost.aspx?PostID=171594

--
William Stacey [MVP]

"Jamie Bissett" <ja**********@yahoo.com> wrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
|I have an application that creates a pretty intensive TreeView at startup
| time. I had the program running on a single thread sucessfully, but the
| startup time was a bit excessive. When the application starts up it is a
| requirement for the user to log on, so in my magical wisdom, I thought
shove
| all this processing on another thread, so it loads while the user logs on.
I
| have all the code running on the thread OK, but I cannot figure out how to
| return the data to the main thread so that I can update the UI from the
main
| thread.
|
| In the BackgroundWorker task I have created a new TreeView that is not
| attached to any UI. I build this in the background, I then attempted to
Pass
| this back through an MSMQ Queue, but unfortunately the TreeView class in
non
| Serializable so the Queue.Send fails.
|
| Can someone please explain to the best way to return this data to the main
| thread.
|
| Thanks in advance
|
| Jamie
|
|


感谢您提供的信息William,

我有实现了这个模型,是的它确实有效,但它给我带来了一个小的视觉问题。


我在启动时做的是启动另一个线程你在模型中描述了
提供了我,我隐藏了主窗体(上面有树视图)和diaply

a登录对话框。

现在发生的事情就是它看到,要延迟绘制

登录对话框,即边框在

dilaog中以纯白色背景绘制,然后大约2秒后,dilaog填充。


任何想法?


Jamie

Jamie Bissett < JA ********** @ yahoo.com>在消息中写道

新闻:uU ************** @ TK2MSFTNGP02.phx.gbl ...
Thanks for the info William,
I have implemented this model and yes it does work, but it is causing me a
little visual problem.

What I do at startup is start the other thread as described in the model you
provided me, I hide the main form (which has the treeviews on it) and diaply
a login dialog.
What is happening now is that it see,s to delay the the painting o f the
login dialog i.e. the borders draw with a plain white background in the
dilaog then about 2 secs later the dilaog fills.

Any ideas?

Jamie
"Jamie Bissett" <ja**********@yahoo.com> wrote in message
news:uU**************@TK2MSFTNGP02.phx.gbl...
我有一个应用程序在启动时创建一个非常密集的TreeView。我让程序成功运行在单个线程上,但启动时间有点过分。当应用程序启动时,它是用户登录的要求,所以在我的神奇智慧中,我认为
将所有这些处理推到另一个线程上,所以它在用户加载时
登录。我已经在线程上运行了所有代码,但我无法确定如何将数据返回到主线程,以便我可以从主线程更新UI。
<在BackgroundWorker任务中,我创建了一个没有附加到任何UI的新TreeView。我在后台构建了这个,然后尝试通过MSMQ队列将其传回,但不幸的是TreeView类在非Serializable中,因此Queue.Send失败。

有人可以解释一下将这些数据返回主线程的最佳方式。

提前致谢

Jamie
I have an application that creates a pretty intensive TreeView at startup
time. I had the program running on a single thread sucessfully, but the
startup time was a bit excessive. When the application starts up it is a
requirement for the user to log on, so in my magical wisdom, I thought
shove all this processing on another thread, so it loads while the user
logs on. I have all the code running on the thread OK, but I cannot figure
out how to return the data to the main thread so that I can update the UI
from the main thread.

In the BackgroundWorker task I have created a new TreeView that is not
attached to any UI. I build this in the background, I then attempted to
Pass this back through an MSMQ Queue, but unfortunately the TreeView class
in non Serializable so the Queue.Send fails.

Can someone please explain to the best way to return this data to the main
thread.

Thanks in advance

Jamie



可能在显示对话框后等待启动线程。听起来像

也许线程做了很多工作而且不允许UI事件。另外

在隐藏表单上构建UI时暂停更新,并在完成更新后恢复更新




-

William Stacey [MVP]


" Jamie Bissett" < JA ********** @ yahoo.com>在消息中写道

新闻:ey ************** @ TK2MSFTNGP03.phx.gbl ...

|感谢您的信息William,

|我已经实现了这个模型,是的它确实有效,但它让我感到很好

a

|小视觉问题。

|

|我在启动时做的是启动模型中描述的另一个线程



|提供给我,我隐藏了主要表格(上面有树视图)和

diaply

|登录对话框。

|现在发生的事情就是它看到了延迟绘画的价格

|登录对话框,即

|中的边框用纯白色背景绘制dilaog然后大约2秒后dilaog填充。

|

|有什么想法吗?

|

|杰米

| Jamie Bissett < JA ********** @ yahoo.com>在消息中写道

|新闻:uU ************** @ TK2MSFTNGP02.phx.gbl ...

| >我有一个应用程序在启动时创建一个非常密集的TreeView

| >时间。我让程序成功运行在单个线程上,但是

| >启动时间有点过分。当应用程序启动时,它是一个

| >要求用户登录,所以在我的神奇智慧中,我想是

| >在另一个线程上推送所有这些处理,因此在用户加载时会加载

| >登录。我已经在线程上运行了所有代码OK,但我不能

数字

| >了解如何将数据返回到主线程,以便我可以更新UI

| >来自主线程。

| >

| >在BackgroundWorker任务中,我创建了一个不是
|的新TreeView >附加到任何UI。我在后台构建了这个,然后尝试了

| >通过MSMQ队列将其传回,但不幸的是TreeView



| >在非Serializable中,Queue.Send失败。

| >

| >有人可以解释一下将这些数据返回给

主要的最佳方式

| >线程。

| >

| >在此先感谢

| >

| >杰米

| >

|

|
Maybe wait to start the thread after your dialog is displayed. Sounds like
maybe the thread is doing much work and not allowing UI events. Also
Suspend updates while building the UI on the hidden form and Resume updates
on the control after updates are done.

--
William Stacey [MVP]

"Jamie Bissett" <ja**********@yahoo.com> wrote in message
news:ey**************@TK2MSFTNGP03.phx.gbl...
| Thanks for the info William,
| I have implemented this model and yes it does work, but it is causing me
a
| little visual problem.
|
| What I do at startup is start the other thread as described in the model
you
| provided me, I hide the main form (which has the treeviews on it) and
diaply
| a login dialog.
| What is happening now is that it see,s to delay the the painting o f the
| login dialog i.e. the borders draw with a plain white background in the
| dilaog then about 2 secs later the dilaog fills.
|
| Any ideas?
|
| Jamie
| "Jamie Bissett" <ja**********@yahoo.com> wrote in message
| news:uU**************@TK2MSFTNGP02.phx.gbl...
| >I have an application that creates a pretty intensive TreeView at startup
| >time. I had the program running on a single thread sucessfully, but the
| >startup time was a bit excessive. When the application starts up it is a
| >requirement for the user to log on, so in my magical wisdom, I thought
| >shove all this processing on another thread, so it loads while the user
| >logs on. I have all the code running on the thread OK, but I cannot
figure
| >out how to return the data to the main thread so that I can update the UI
| >from the main thread.
| >
| > In the BackgroundWorker task I have created a new TreeView that is not
| > attached to any UI. I build this in the background, I then attempted to
| > Pass this back through an MSMQ Queue, but unfortunately the TreeView
class
| > in non Serializable so the Queue.Send fails.
| >
| > Can someone please explain to the best way to return this data to the
main
| > thread.
| >
| > Thanks in advance
| >
| > Jamie
| >
|
|


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

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