我正在使用Timer
并让它执行常规检查。如果测试条件为真,那么我启动一个线程,让它执行它必须做的事情。
如果在该线程中,我想更改UI,请使用InvokeOnMainThread()
。但是,由于该线程是由已经是一个单独线程的Timer
触发的,因此InvokeOnMainThread()
将在Timer的线程而不是实际的主线程上调用事物。我通过将两个InvokeOnMainThread()
调用装箱来解决此问题。
这是按预期的方式工作还是Mono框架中的错误?
主线程是定义为触发当前线程的线程还是应该返回“根”线程?
最佳答案
NSObject.InvokeOnMainThread
在大多数情况下是performSelectorOnMainThread:withObject:waitUntilDone:的包装
引用文档:
You can use this method to deliver messages to the main thread of your application. The main thread encompasses the application’s main run loop, and is where the NSApplication object receives events.
如果您在http://bugzilla.xamarin.com上填写了一个错误报告以及一个自包含的测试用例,我们可以对其进行更深入的研究(似乎很奇怪)。
关于multithreading - InvokeOnMainThread()不一定要在主线程上调用-错误或功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8326937/