开发者

WindowsFormsSynchronizationContext locks for a long time on Post

开发者 https://www.devze.com 2023-04-06 07:52 出处:网络
I have been looking at the delay/lock of posting asynchronously to a WindowsFormsSynchronizationContext and have discovered that this uses the Control.MarshaledInvoke method, which has two locks insid

I have been looking at the delay/lock of posting asynchronously to a WindowsFormsSynchronizationContext and have discovered that this uses the Control.MarshaledInvoke method, which has two locks inside! Since, the SynchronizationContext uses a global Control (the Application.MarshalingControl) one is effectively hitting a single lock and, thus, a 开发者_运维技巧throughput limit when using this.

Something, we have witnessed several times can result in very long delays e.g. when connecting to a machine through Remote Desktop it appears the controls are locked for a long time.

My question is, has anyone encountered this issue? And any suggestion for a solution?

I am contemplating putting the actual Post on the thread pool using Task.Run... but this would give an additional overhead. Our main concern here is the the thread posting asynchronously should not be locked for a long time > 1 ms, so I guess putting the action on a task would work, but this also introduces GC pressure.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号