【问题标题】:WindowsFormsSynchronizationContext execution order of posted callbacks已发布回调的 WindowsFormsSynchronizationContext 执行顺序
【发布时间】:2021-08-03 14:18:07
【问题描述】:

我使用WindowsFormsSynchronizationContext 在主 UI 线程(应用程序是 WinForms)中调度回调的执行。调度回调代码在工作线程中运行,它不应该与回调同步,所以我使用WindowsFormsSynchronizationContext.Post() 方法。但是回调必须在主 UI 线程中执行,以便在WindowsFormsSynchronizationContext 中发布它们。

有人知道WindowsFormsSynchronizationContext 是否按发布顺序执行发布的回调吗? 我在Microsoft Docs中没有找到这个信息。

【问题讨论】:

    标签: c# winforms synchronization


    【解决方案1】:

    是的,订单被保留。

    WindowsFormSynchronizationContext.Post 调用Control.BeginInvoke 调用MarshaledInvoke 调用PostMessage

    The order among messages which are posted to a window is preserved(但发送的消息优先于发布的消息)。

    【讨论】:

      猜你喜欢
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2016-03-05
      • 1970-01-01
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多