六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

Dot Net的調(diào)試 - 3

[摘要]調(diào)試 實際上調(diào)試和跟蹤用得很普遍。Debug類中的方法有相同的名字的方法,這些方法實現(xiàn)了調(diào)試的功能。不同之處是在發(fā)布版本配置中是禁止使用的(這意味著不能產(chǎn)生二進制代碼調(diào)用這些代碼)。調(diào)試輸出也可...
調(diào)試



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

<confuration>

<system.diagnostics>

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

</system.diagnostics>

</confuration>

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



設(shè)置調(diào)試開關(guān)

最后討論的主題是Switch。Switch是有一些狀態(tài)的對象�?梢栽谂渲梦募蛘呔幊痰臅r候改變狀態(tài)。Switch讓你創(chuàng)建可配置的調(diào)試跟蹤代碼。最好了解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依照他們的狀態(tài)創(chuàng)建輸出信息。Switch狀態(tài)由TraceErrror,TraceInfo,TraceVerbose和TraceWarning屬性檢查。這些屬性檢查switch狀態(tài)和如果trace級別等于或大于相應(yīng)的常量,那么將返回true。例如,當(dāng)這個級別是2或者更大那么TraceWarning是true,下面表格是返回值:

TraceErroe
1

TraceWarning
2

TraceInfo
3

TraceVerbose
4


但是,正如我們已經(jīng)說的,switch的狀態(tài)可以在代碼中修改,做個修改代碼的范例:

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層次。



計算性能

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

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個整數(shù)和輸出素數(shù)。調(diào)試的目的是測試每一個輸出數(shù)字,不管是否是素數(shù)。如果數(shù)字不是素數(shù),那么輸出failed.

對比測量下帶調(diào)試和不帶調(diào)試的時間:


1
2
3

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

不帶調(diào)試功能

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


可以看出調(diào)試是昂貴的—例子中花費了64%的執(zhí)行時間



結(jié)論:

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





標(biāo)簽:Dot Net的調(diào)試 - 3 
主站蜘蛛池模板: 日本一区二区三区精品 | 青青青在线网站视频在线 | 日韩永久免费视频 | 日本视频在线免费观看 | 天天干天天色天天干 | 色婷婷丁香六月 | 亚洲成a人v天堂网 | 日本韩国在线视频 | 天堂新版8中文在线8 | 色花堂国产精品首页第一页 | 日韩在线观看网址 | 涩涩国产精品福利在线观看 | 日本一区二区三区在线观看视频 | 色噜噜狠狠色综合中文字幕 | 午夜精品福利影院 | 色吧亚洲欧美另类 | 亚洲欧美中文日韩在线v日本 | 欧洲亚洲综合 | 夜鲁鲁鲁夜夜综合视频欧美 | 日韩性网 | 伊人久久大香线蕉资源 | 亚欧在线精品免费观看一区 | 先锋资源国产 | 中文字幕在线看视频一区二区三区 | 欧美一区二区三区在观看 | 午夜在线视频 | 色又色| 日日躁夜夜躁狠狠天天 | 天天躁日日躁 疯人影院 | 天天干夜夜想 | 色综合久久天天综线观看 | 日韩污| 日韩一区二区中文字幕 | 天天爱天天插 | 色婷婷激婷婷深爱五月老司机 | 手机看片国产在线 | 特级毛片全部免费播放a一级 | 欧美一级三级 | 午夜大片在线观看 | 日本aⅴ永久免费网站www | 青青青青青国产免费手机看视频 |