Concurrency issue RRS feed

  • Question

  • I am currently studying WCF  and encountered a problem when invoking two method concurrently with same client proxy object.

    1. My first method will sleep the calling thread for 20 second

    2. When I invoke the second function before the first function return, it hangs.

    3. This will happen only on the first attempt and every subsequent invocation works fine.

    Please find the modified sample code here

     [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, ConcurrencyMode=ConcurrencyMode.Multiple, UseSynchronizationContext=false)]

    public class MessagingService : IMessagingService


             public void SendMessage1(string message)

    // Sleep the thread for 20 second


             public void SendMessage2(string message)



    Thursday, November 21, 2013 2:02 AM


  • Hi,

    I see that you are using:

     [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, ConcurrencyMode=ConcurrencyMode.Multiple, UseSynchronizationContext=false)]

    In the above mode, we only use single thread for every client, so we can not invoke two method concurrently. Please try to use the PerSession mode as following:

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession, ConcurrencyMode=ConcurrencyMode.Multiple)]

    For more information, please try to check this table:

    #WCF Concurrency: .

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 22, 2013 6:07 AM