InstanceContext.SynchronizationContext 属性

定义

获取或设置与当前实例上下文一起用于线程同步的上下文。

public:
 property System::Threading::SynchronizationContext ^ SynchronizationContext { System::Threading::SynchronizationContext ^ get(); void set(System::Threading::SynchronizationContext ^ value); };
public System.Threading.SynchronizationContext SynchronizationContext { get; set; }
member this.SynchronizationContext : System.Threading.SynchronizationContext with get, set
Public Property SynchronizationContext As SynchronizationContext

属性值

SynchronizationContext

与当前实例上下文一起用于线程同步的 SynchronizationContext

例外

该通信对象已打开或正在关闭,并且在这些状态下不能修改。

该通信对象已中止,并且在这些状态下无法修改。

该通信对象已关闭,并且在这些状态下无法修改。

该通信对象处于错误状态,并且在这些状态下无法修改。

示例

Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/service");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    serviceHost.Open();
    OperationContext operationContext = OperationContext.Current;
    InstanceContext instanceContext = operationContext.InstanceContext;
    SynchronizationContext syncCon = instanceContext.SynchronizationContext;
}

适用于