简体   繁体   English

移动到非UI类中的主线程

[英]Move to the main thread in a non-UI class

In a function running in a non-UI application: 在非UI应用程序中运行的函数中:

void MyFunctionThatIsACallBack() {}

What options do I have to force the code in MyFunction() so that it runs in the main thread? 我有什么选项来强制MyFunction()中的代码,以便它在主线程中运行?

The function is a call back from another section of code that may or may not be in the main tread. 该函数是来自另一部分代码的回调,该代码部分可能或可能不在主要部分中。

This isn't as simple a question as it seems. 这并不像看起来那么简单。 The main thread would need to be running in a loop, reading work items off of a queue and processing them. 主线程需要在循环中运行,从队列中读取工作项并处理它们。 You can't just usurp a thread's context and make it do some arbitrary other thing. 你不能只是篡夺一个线程的上下文,并让它做一些随意的事情。

My suspicion is that there is some deeper threading issue that you are seeing, and this probably isn't the way to solve it. 我怀疑你看到的是一些更深层次的线程问题,这可能不是解决问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM