当在不同的应用程序域运行SynchronizationContext.Current为null [英] SynchronizationContext.Current is null when run on different app domains
问题描述
我在一台机器一个Web应用程序运行,并在另一台机器服务(i.e.both在不同的应用程序域)。我在后者从SynchronizationContext.Current的Synschronization方面,我国服务层有一个工作流服务。我得到的总是SynchronizationContext.Current为NULL。但是,如果我跑我的两个在同一台机器的应用和服务层(即相同的AppDomain)的SynchronizationContext.Current是AspNetSynchronizationContext,它工作正常。有人可以帮我解决这个运行不同的应用程序域。
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 gets the Synschronization Context from SynchronizationContext.Current. I get the SynchronizationContext.Current always as null. But If I run both my application and service layer in the same machine (i.e. same appdomain) the SynchronizationContext.Current is AspNetSynchronizationContext and it works fine. Can somebody help me to resolve this to run different app domains.
推荐答案
我解决它通过overiding同步上下文
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);
}
}
这篇关于当在不同的应用程序域运行SynchronizationContext.Current为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!