DefaultTraceListener.AssertUiEnabled 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示应用程序是否以用户界面模式运行。
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