ServiceHost.OnClosed 方法

定义

当服务主机关闭时,释放所承载的可处置服务。

protected:
 override void OnClosed();
protected override void OnClosed ();
override this.OnClosed : unit -> unit
Protected Overrides Sub OnClosed ()

注解

重写 OnClosed 方法时,必须确保基数。调用 OnClosed 方法,即使发生异常也是如此。 以下代码演示了如何执行此操作。

protected override void OnClosed()  
{  
    try  
    {  
        if (FaultFlagService.faultFlag == ThrowDuring.OnClosed)  
        {  
            FaultFlagService.faultFlag = ThrowDuring.Never;  
            throw new ServiceActivationException("Faulting the service because FaultFlagService.faultFlag = ThrowDuring.OnClosed");  
        }  
    }  
    finally  
    {  
        base.OnClosed();  
    }  
}  

适用于