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

问题描述

我已经设置了这个帖子,所以当我调用cpu时我的程序没有挂起

密集的代码:


System.Threading .ThreadStart ThreadEncoderStart = new

System.Threading.ThreadStart(myEncoder.EncodeFromC onsole);

System.Threading.Thread Thread_myEncoder = new

系统.Threading.Thread(ThreadEncoderStart);

Thread_myEncoder.Name =" myEncoder";

Thread_myEncoder.Priority =

System.Threading.ThreadPriority .BelowNormal;

Thread_myEncoder.Start();


反过来我会在for循环中调用它:

for(int x = 0; x< = lbxVideo.Items.Count -1; x ++){

EncodeThread();

}


我的问题是如何按顺序完成线程,例如第一个

时间运行线程,但让主线程等到它的

完成后继续下一个for语句?


。感谢任何帮助。

I have set up this thread so my program doesn''t hang while I call a cpu
intensive bit of code:

System.Threading.ThreadStart ThreadEncoderStart = new
System.Threading.ThreadStart(myEncoder.EncodeFromC onsole);
System.Threading.Thread Thread_myEncoder = new
System.Threading.Thread(ThreadEncoderStart);
Thread_myEncoder.Name = "myEncoder";
Thread_myEncoder.Priority =
System.Threading.ThreadPriority.BelowNormal;
Thread_myEncoder.Start();

In turn I''m calling this from within a "for loop":
for (int x = 0; x <= lbxVideo.Items.Count -1; x++) {
EncodeThread();
}

My problem is how to I make the threads complete in sequence e.g. first
time around run the thread but make the main thread wait until its
finished before proceeding with the next for statement?

any help would be gratefully appreciated.

推荐答案




有主线程运行:


System.Threading.Thread.Join(Thread_myEncoder);


这将阻止主线程,直到目标线程完成。


大卫



Have the main thread run:

System.Threading.Thread.Join(Thread_myEncoder);

This will block the main thread until the target thread finishes.

David






如果你打算这样做,你也可以运行代码在

开始的主线程。


Jon



If you''re going to do that though, you might as well run the code in
the main thread to start with.

Jon


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

10-25 05:41