문제

I write the WCF application. In service i have method and i want sync this method to all customers. So one client can use this method at the moment and rest client waiting when first client finish. I try [MethodImpl(MethodImplOptions.Synchronized)] but this not work. This is my service class

namespace WcfServiceLibrary1 {
    [ServiceBehavior(UseSynchronizationContext = false)]
    public class Service1 : IService1 {


        [MethodImpl(MethodImplOptions.Synchronized)]
        public List<String> getBrute() {
           //method body
        }
     }
}

How does synchronization methods in WCF?

도움이 되었습니까?

해결책

I think that setting only really makes sense in the context of a duplex binding (a callback) where the client has registered a callback from the server to the client. It is a slightly exotic situation. It basically says when you receive this callback from the server invoke it onto the main thread, rather than just running it on some arbitrary thread pool thread.

To do what you want, you need to create an explicit lock on the server:

public class Service1 : IService1 {
    private static readonly object @lock = new object();

    public List<String> getBrute() {
       lock (@lock)
       {
           //method body
       }
    }
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top