作业帮 > 英语 > 作业

英语翻译There are quite a few issues here:1) You can leave this

来源:学生作业帮 编辑:神马作文网作业帮 分类:英语作业 时间:2024/11/19 09:09:04
英语翻译
There are quite a few issues here:
1) You can leave this in the main thread.Unless the main thread is going to be doing some work of its own,there is no reason to have a secondary thread for the loop.
2) Since you have to update some global state "almost continuously",you'll need to have processing that's occurring very regularly.This eliminates blocking on events.
My recommendation would be to move your while(..) loop into your main thread - you don't need the second one.
You could then have it update your global state,and do any event processing from the queue.In order to prevent the huge CPU usage,have the main thread sleep for a short interval every time.It could look like:
while(!exitCondition)
{
UpdateGlobalState();
ProcessEventQueue();
System.Threading.Thread.Sleep(10); // Sleep for a short period here,to avoid huge,unnecessary CPU usage
}
英语翻译There are quite a few issues here:1) You can leave this
有相当多的话题.
1)你就可以离开这个在主线.除非主线会做一些工作自身,没有理由有中等线的循环.
二),因为你要更新一些全球国家“几乎没有”,你将需要处理,经常发生的.这就消除阻塞.
我建议你将移动时,(……)回路进入你的主线,你不需要另一个.
然后你就可以拥有它更新你的全球性的状态,并做任何事件处理从队列中.为了防止巨大的CPU时间,有主线睡一段间隔时间.它看起来就像.
虽然(!exitCondition).
{
UpdateGlobalState().
ProcessEventQueue().
System.Threading.Thread.Sleep(10);/ /睡在短时间内,以避免不必要的CPU巨大
}