共用方式為


DefaultTraceListener.AssertUiEnabled 屬性

定義

取得或設定值,表示應用程式是否正在使用者介面模式下執行。

public:
 property bool AssertUiEnabled { bool get(); void set(bool value); };
public bool AssertUiEnabled { get; set; }
member this.AssertUiEnabled : bool with get, set
Public Property AssertUiEnabled As Boolean

屬性值

如果具有使用者介面模式,則為 true,否則為 false

範例

下列程式代碼範例會呼叫 呼叫 方法的 Fail(String, String) 函式,以在函式擲回例外狀況時記錄錯誤訊息。 AssertUiEnabled如果屬性為 false,方法也會將錯誤訊息寫入主控台。

// Compute the next binomial coefficient and handle all exceptions.
try
{
    result = CalcBinomial(possibilities, iter);
}
catch(Exception ex)
{
    string failMessage = String.Format("An exception was raised when " +
        "calculating Binomial( {0}, {1} ).", possibilities, iter);
    defaultListener.Fail(failMessage, ex.Message);
    if (!defaultListener.AssertUiEnabled)
    {
        Console.WriteLine(failMessage+ "\n" +ex.Message);
    }
    return;
}
' Compute the next binomial coefficient and handle all exceptions.
Try
    result = CalcBinomial(possibilities, iter)
Catch ex As Exception
    Dim failMessage As String = String.Format( _
            "An exception was raised when " & _
            "calculating Binomial( {0}, {1} ).", _
            possibilities, iter)
    defaultListener.Fail(failmessage, ex.Message)
    If Not defaultListener.AssertUiEnabled Then
        Console.WriteLine(failMessage & vbCrLf & ex.Message)
    End If
    Return
End Try

適用於