Why are my message be processed out of order over a single WCF TCP channel (with ConcurrencyMode.Reentrant)?

后端 未结 3 617
猫巷女王i
猫巷女王i 2021-01-05 22:45

The client sends a lot of messages to the server from a single thread, over a single WCF channel.

The client sends the message with BeginMyMethod(x, b) as it does

3条回答
  •  醉梦人生
    2021-01-05 23:06

    I have now worked round this problem by:

    • Changing all my call-backs from the server to the client to be OneWay
    • Using a dispatcher in the client before passing on any callback from the server, so client code never calls the sever from within a call-back
      • The client call-back object is marked with CallbackBehavior(UseSynchronizationContext=false, ConcurrencyMode=ConcurrencyMode.Single)
      • When running in Winform or WPF I use SynchronizationContext.Post to depatch the callbacks
      • When the cleint is a Console or a Windows server I use a custom depatcher.
    • So letting me use ConcurrencyMode.Single on both the server and the client.

    It is now working as expected.
    (BeginMyMethod(x, b) is still being used to send messaged from the client to the server)

    (ConcurrencyMode.Reentrant seems to sometimes release the lock even when the WCF call is not made on the some thread that is processing the incoming message, it is just not a useful as Reentrant was in DCOM)

提交回复
热议问题