日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當前位置:雨林木風下載站 > 技術開發教程 > 詳細頁面

Dot Net的調試 - 3

Dot Net的調試 - 3

更新時間:2022-05-07 文章作者:未知 信息來源:網絡 閱讀次數:

調試



實際上調試和跟蹤用得很普遍。Debug類中的方法有相同的名字的方法,這些方法實現了調試的功能。不同之處是在發布版本配置中是禁止使用的(這意味著不能產生二進制代碼調用這些代碼)。調試輸出也可以在配置文件設置,請看下面:

<confuration>

<system.diagnostics>

<debug autoflush = “true” indentsize = “7” / >

</system.diagnostics>

</confuration>

備注:調試的聲明和語法和跟蹤很類似。不同之處,就是把有Trace的地方替換為Debug



設置調試開關

最后討論的主題是Switch。Switch是有一些狀態的對象。可以在配置文件或者編程的時候改變狀態。Switch讓你創建可配置的調試跟蹤代碼。最好了解Switch的方法是寫一個段簡單代碼,如下:

using System;

using System.Diagnostics;



namespace Switching

{

class SampleClass

{

//Create a Switch. It is initialized by an externally specified value

static TraceSwitch generalSwitch = new TraceSwitch(“CoolSwitch”, “Global Scope”);

static public void SampleMethod()

{

//The first message is written if the switch state is set to TraceError

if(generalSwitch.TraceError)

console.WriteLine(“TraceError message”);

//The second message is written if the switch state is set to TraceVerbose

if (generalSwitch.TraceVerbose)

Console.WriteLine(“TraceVerbose message”);

//The third message is writeen if the switch state is set to TraceWarning

if (generalSwitch.TraceWarning)

Console.WriteLine(“TreaceWarning message”);

//The fourth message is written if the switch state is set to TraceInfo

if(generalSwitch.TraceInfo)

Console.WriteLine(“TraceInfo Message”);

}

public static void Main(string[] args)

{

//calls the sampleMethod method

SampleMethod();

}

}

}



有幾個switch類:TraceSwitch和BooleanSwitch。這個例子中我們用使用TraceSwitch依照他們的狀態創建輸出信息。Switch狀態由TraceErrror,TraceInfo,TraceVerbose和TraceWarning屬性檢查。這些屬性檢查switch狀態和如果trace級別等于或大于相應的常量,那么將返回true。例如,當這個級別是2或者更大那么TraceWarning是true,下面表格是返回值:

TraceErroe
1

TraceWarning
2

TraceInfo
3

TraceVerbose
4


但是,正如我們已經說的,switch的狀態可以在代碼中修改,做個修改代碼的范例:

using System;

using System.Diagnostics;



namespace Switching

{

class SampleClass

{

//Create a Switch. It is initialized by an externally specified value

static TraceSwitch generalSwitch = new TraceSwitch(“CoolSwitch”, “Global Scope”);

static public void SampleMethod()

{

//The first message is written if the switch state is set to TraceError

if(generalSwitch.TraceError)

console.WriteLine(“TraceError message”);

//The second message is written if the switch state is set to TraceVerbose

if (generalSwitch.TraceVerbose)

Console.WriteLine(“TraceVerbose message”);

//The third message is writeen if the switch state is set to TraceWarning

if (generalSwitch.TraceWarning)

Console.WriteLine(“TreaceWarning message”);

//The fourth message is written if the switch state is set to TraceInfo

if(generalSwitch.TraceInfo)

Console.WriteLine(“TraceInfo Message”);

}

public static void Main(string[] args)

{

Console.WriteLine(“Before manual level set\n”);

SampleMethod();

GeneralSwitch.Level = TraceLevel.Warning;

SampleMethod();

}

}

運行程序,包含以下信息:



Before manual level set



TraceError Message

TraceWarning message

TraceInfo message



After manual level set



TraceError Message

TraceWarning Message



這些展示了改變trace switch層次。



計算性能

這部分我們將告訴你調試的花費時間。事實上,調試對于商業邏輯不起作用。但是調試代碼需要花費時間。我們將計算應用程序中輸出信息的花費時間。當你測試一個是建要求嚴格的應用程序時間,測量就很重要。看下面的代碼:

using system;

using system.Diagnostics;



namespace DebugDemo

{

class PrimeNumberDetector

{

public static bool IsPrime(int n)

{

int upperbound = (int)Math.Sqrt(n);

for (int I = 2; I <= upperbound; I++)

{

Debug.WriteLine(“Processing number” + n + “, Testing with “ + i);

If((n%i) == 0)

{

Debug.WriteLine(“FAILED”);

Return false;

}

}

}



public Application

{

[STAThread]

static void Main(string[] args)

{

for(int i = 2; i < 10000;i++)

if (PrimeNumberDetector.IsPrime(i))

Console.WriteLine(“{0} is prime number” , i);

}

}

}

程序測試2到1000個整數和輸出素數。調試的目的是測試每一個輸出數字,不管是否是素數。如果數字不是素數,那么輸出failed.

對比測量下帶調試和不帶調試的時間:


1
2
3

帶調試功能(hh:mm:ss.ff)
00:00:07.9714624
00:00:07.9414192
00:00:07.9714624

不帶調試功能

(hh:mm:ss.ff)
00:00:05.1273728
00:00:05.5179344
00:00:05.1273728


可以看出調試是昂貴的—例子中花費了64%的執行時間



結論:

文章中描述了調試跟蹤.net程序的一般方法。當然還有一些其他問題,如,條件編譯我們沒有做。想學到更多的東西,可以看msdn。我們希望這篇文章幫助你掌握調試跟蹤.net程序的技術。


溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

主站蜘蛛池模板: 中国一级毛片 | 久久视频在线播放视频99re6 | 日本在线 | 中文 | 91精品久久久久久久久久 | 亚洲精品98久久久久久中文字幕 | 4hu四虎免费影院www | 日韩精品久久久久久 | 久久亚洲精品中文字幕二区 | 日韩精品在线视频 | 视频三区 | 午夜在线视频国产极品片 | 国产在线丝袜 | 高清大学生毛片一级 | 免费的毛片视频 | 精品国产一二三区 | 男女高清性高爱潮免费 | 国产精品美女一区二区 | 最新日韩在线观看 | 欧美成人禁片在线观看网址 | 波多野结衣高清在线播放 | 亚洲欧美久久久久久久久久爽网站 | 国产三级日本三级日产三级66 | 一个人看的www免费高清视频 | 黄色青青草 | 亚洲欧美在线观看播放 | 色综合小说久久综合图片 | 在线观看免费视频国产 | 日韩亚洲人成在线 | 日韩欧美精品综合一区二区三区 | 久久伊人中文字幕麻豆 | 日本亚洲天堂网 | 欧美日韩国产综合视频在线看 | 久久亚洲国产最新网站 | 日韩一级特黄 | 五月天激激婷婷大综合蜜芽 | 色婷婷综合久久久中文字幕 | 天天射天 | 夜夜躁天天躁很很躁 | 欧洲性开放大片免费观看视频 | 91在线品视觉盛宴免费 | 在线免费日本 |