Invoke delegate on main thread in console application

前端 未结 3 1417
我在风中等你
我在风中等你 2020-12-18 07:59

In a Windows Application, when multiple threads are used, I know that it’s necessary to invoke the main thread to update GUI components. How is this done in a Console Applic

3条回答
  •  失恋的感觉
    2020-12-18 08:43

    Typically it's not done in a console app. If you're trying to use a Win32 GUI API, you should really be running a message loop, I suspect.

    You could call Application.Run() or Application.Run(ApplicationContext) from your console app to start a new message loop. The idea would be to then use SynchronizationContext.Current to marshal back to the main thread. However, I haven't managed to get that to work yet... you need to somehow force it to register its message loop as the current synchronization context, and I haven't managed to persuade it to do so :(

提交回复
热议问题