none
why CallbackBehavior use UseSynchronizationContext as true by default? RRS feed

  • Question

  • Hi All:

    We encountered some very strange behavior recently, the client called unsubscribe() to one wcf service to log off, in most case it works fine, however sometime it throws timeout exception, even the server side is in idle, I scratch my head the whole day to find  culprit, eventually it turns out a deadlock between wcf callback and wcf service method. after apply CallbackBehavior(UseSynchronizationContext=false), it works fine.

    So my question is why this value is true by default? it makes troubles to most desktop developer, because most of us use UI thread to issue wcf calls.

    Kind regards


    fight for future!

    Thursday, March 23, 2017 6:13 AM

Answers

  • >>So my question is why this value is true by default?

    As you know, WCF has been developed for a long time, ServiceBehaviorAttribute.UseSynchronizationContext Property is added from .NET Framework 3.0. At that time, I assume most desktop developer register Windows Forms application as a singleton service object. In this case, all calls into the service must run on the Windows Forms thread. The default case, in which UseSynchronizationContext is set to true, synchronizes all calls to the service to run on the thread captured from the System.Threading.SynchronizationContext.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Mulder2008 Friday, March 24, 2017 7:11 AM
    Friday, March 24, 2017 2:21 AM

All replies

  • >>So my question is why this value is true by default?

    As you know, WCF has been developed for a long time, ServiceBehaviorAttribute.UseSynchronizationContext Property is added from .NET Framework 3.0. At that time, I assume most desktop developer register Windows Forms application as a singleton service object. In this case, all calls into the service must run on the Windows Forms thread. The default case, in which UseSynchronizationContext is set to true, synchronizes all calls to the service to run on the thread captured from the System.Threading.SynchronizationContext.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Mulder2008 Friday, March 24, 2017 7:11 AM
    Friday, March 24, 2017 2:21 AM
  • Thanks for your reply.

    I hope false will be used as default value as CallbackBehavior(UseSynchronizationContext=false) in next WCF version.


    fight for future!

    Friday, March 24, 2017 7:13 AM