多线程问题......帮助 [英] multi-threading problem...help
问题描述
好的,
我有一个线程,我在用户点击开始时启动:
ThreadStart myThreadDelegate = new ThreadStart
ThreadFunction1.getOneAtATime);
线程thr1 =新线程(myThreadDelegate);
thr1.Start();
进程开始包含一个非常大的函数,它在一个连续循环的
中(这里只是为了演示我的问题):
foreach(字符串发票)在Class1.invoiceHolder中)
{
//不断显示状态栏
//不断更新图像控制如果托盘有纸或不是。
//不断更新显示发票信息的标签
}
好的,
这需要在这个循环中一次运行几天......但是,如上所述,我在线程中有了它的b $ b,应用程序就会退出。
我之前发过一个问题并得到了答案
"控件创建者在其他线程中启动的
进程不应触及初始化线程(创建不良结果)。好的,
我明白了,但是当我开始运行这个帖子时,它必须给
用户更新。
好的,我看了在Control.Invoke并没有得到它。我的意思是,我/ b $ b无法弄清楚如何使用它(精神障碍)。这是我的问题的答案吗? (问题是,如果我没有在单独的线程中启动这个巨大的进程,当它在这个循环中启动时,计算机开始
爬行)。 br />
帮助表示赞赏。
谢谢,
Trint
Ok,
I have a thread that I start when user clicks to start:
ThreadStart myThreadDelegate = new ThreadStart
ThreadFunction1.getOneAtATime);
Thread thr1 = new Thread(myThreadDelegate);
thr1.Start();
The process started contains a Very large function that is in a
continuous loop (here is part of it just to demonstrate my problem):
foreach (string invoice in Class1.invoiceHolder)
{
//Constantly show a status bar
//Constantly update image control of "if tray has paper or not".
//Constantly update labels displaying info about Invoices
}
Ok,
This will need to run for days at a time in this loop...HOWEVER, I had
it in the Thread, as mentioned, and the app would just quit.
I had posted a question to this before and got the answer that
"Controls created by the initializing thread should not be touched by
processes started in other threads (creates undesirable results". Ok,
I get that, but when this thread I start runs, it MUST give updates to
users.
Ok, I have looked at Control.Invoke and don''t get it. I mean that, I
couldn''t figure out how to use it (mental block). Is that the answer to
my problem? (Problem being, that if I don''t start this giant process in
a separate thread, when it starts in this loop, the computer starts to
crawl).
Help is appreciated.
Thanks,
Trint
推荐答案
我应该启动两个线程,一个执行工作,一个(使用计时器)
每隔xxx时间更新一次用户状态。
但是......你为什么不做一个与前端通信的服务?
QueueMessage或其他技术?
I whould start two thread, one that do the work, and one (using timers)
that updates the status to the user every xxx time.
But... why don''t you do a service that comunicate with a front-end with
QueueMessage or other tecnics?
不错,但是他们已经批准了表格上的控件外观
。
我确实需要这个大功能虽然在一个新的线程中。
谢谢。
Not a bad idea, but they have already approved the look of the controls
on the forms.
I do need to have this large function in a new thread though.
Thanks.
你好Trint ..
这篇文章是在VB中并且解释了很多关于线程并在它们之间传递
的值,看它是否有帮助
http://www.devx.com / dotnet / Article / 11358/1954?pf = true
VJ
" trint" < TR *********** @ gmail.com>在消息中写道
news:11 ********************** @ z14g2000cwz.googlegr oups.com ...
Hi Trint..
This article is in VB and explains pretty much about threads and passing
values between them, see if it helps
http://www.devx.com/dotnet/Article/11358/1954?pf=true
VJ
"trint" <tr***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
不是一个坏主意,但他们已经批准了表格上的控件外观。
我确实需要在一个新的线程中拥有这个大功能。
谢谢。
Not a bad idea, but they have already approved the look of the controls
on the forms.
I do need to have this large function in a new thread though.
Thanks.
这篇关于多线程问题......帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!