WCF “Fire and Forget” method is not allowing host execution to continue as expected

StackOverflow https://stackoverflow.com/questions/5964240

  •  12-11-2019
  •  | 
  •  

سؤال

I have a windows service hosting a singleton WCF service which caches a large amount of data. On start up of the windows service I am doing the following:

// start client service
        wcfService= new ServiceHost(typeof(MyWcfService));
        wcfService.Open();

        using (HostedServiceReference.WcfServiceProxy wcfServiceProxy = new HostedServiceReference.WcfClientServiceProxy())
        {
            wcfServiceProxy.RefreshDisplayCacheFromSource();
            // 1st echo to console
            Console.WriteLine("Display Cache Refreshed"));
        }
        // 2nd echo to console
        Console.WriteLine("Begin other processing"))

and I have the method configured as follows in the service contract:

[OperationContract(IsOneWay=true)]
    void RefreshDisplayCacheFromSource();

I had expected to immediately see the 1st and 2nd echos displayed in the console, but what I am actually seeing is just the 1st echo. The 2nd line is not displayed until my "fire and forget" method has completed it's long operation.

Can anyone explain what is going on in the background?

My theories so far:

Is the operation of the wcf service in singleton mode blocking the service hosting it?

Is it something to do with the using statement?

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top