暂停执行一个线程没有睡眠? [英] Pausing execution of a Thread WITHOUT sleeping?

查看:154
本文介绍了暂停执行一个线程没有睡眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Skype API,每次收到邮件时都会发回邮件。我不确定这是否真的是什么原因造成的,但它是最接近的:当我发送太多的消息,COM控件不能处理所有的答复,这导致它崩溃整个应用程序当我使用循环的时,会发生这种情况。

I am using the Skype API, which sends back a message everytime it receives one. I am not sure if this really is what is causing it, but it's the closest I can get: When I send too many messages, the COM control can't handle all the replies, which causes it to crash the whole app. That happens when I use a for loop.

我正在使用线程来完成这个工作,所以我的程序赢了不要挂我知道我可以在线程中执行 Sleep(); ,并且(应该)不会使整个程序休眠。问题是,我的COM控件也会睡觉,所以它仍然无法处理任何需要的东西,所以它可以保持再次。

I am using Threads to do the job, so my program won't hang. I know I can do Sleep(); in the thread, and will (should) not make the whole program sleep. The problem is though, that my COM control will be sleeping aswell, so it still wont be able to process whatever it needs, so it can keep up again.

所以,问题是:如何暂停例程而不停止整个线程,以便我的COM对象可以处理回复,而不会重载?

So, the question is: How can I pause the routine without pausing the whole thread, so that the replies can be processed by my COM object, without overloading?

推荐答案

CoWaitForMultipleHandles 可用于阻止线程,但是仍然可以抽取COM消息(在STA的情况下),还有一些其他Windows消息,并且有超时。听起来像你可以使用的东西。

CoWaitForMultipleHandles can be used to block the thread, but still pump COM messages (in case of STA), some other Windows messages and has a timeout. Sounds like something you could use.

这篇关于暂停执行一个线程没有睡眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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