共用方式為


SessionChangeDescription.Reason 屬性

定義

取得工作階段變更的原因。

public:
 property System::ServiceProcess::SessionChangeReason Reason { System::ServiceProcess::SessionChangeReason get(); };
public System.ServiceProcess.SessionChangeReason Reason { get; }
member this.Reason : System.ServiceProcess.SessionChangeReason
Public ReadOnly Property Reason As SessionChangeReason

屬性值

其中一個 SessionChangeReason 值。

範例

下列程式碼範例示範 Reason 在衍生自 ServiceBase 之類別中 方法的 OnSessionChange 實作中使用 屬性。 此程式碼範例是提供給 類別之較大範例的 ServiceBase 一部分。

        // Handle a session change notice
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
#if LOGEVENTS
            EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() +
                " - Session change notice received: " +
                changeDescription.Reason.ToString() + "  Session ID: " +
                changeDescription.SessionId.ToString());
#endif
    ' Handle a session change notice
    Protected Overrides Sub OnSessionChange(ByVal changeDescription As SessionChangeDescription)
#If LOGEVENTS Then
        System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " - Session change notice received: " + changeDescription.Reason.ToString() + "  Session ID: " + changeDescription.SessionId.ToString())
#End If

適用於