SynchronizationContext.Current is null when run on different app domains

后端 未结 2 1360
小蘑菇
小蘑菇 2021-01-27 20:07

I have a Web Application running in one machine and the services in another machine (i.e.both are in different App domains). I have a workflow service in my service layer which

2条回答
  •  情话喂你
    2021-01-27 20:56

    I solved it by overiding the synchronization context

    if (syncContext == null)
    {
       SynchronousSynchronizationContext sync = new SynchronousSynchronizationContext();
       syncContext = sync;
    }
    
    class SynchronousSynchronizationContext : SynchronizationContext
    {
       public override void Post(SendOrPostCallback d, object state)
       {
          this.Send(d, state);
       }
    }
    

提交回复
热议问题