麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

Dot Net的調試 - 3

2024-07-21 02:23:40
字體:
來源:轉載
供稿:網友
調試



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

<confuration>

<system.diagnostics>

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

</system.diagnostics>

</confuration>

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



設置調試開關

最后討論的主題是switch。switch是有一些狀態的對象??梢栽谂渲梦募蛘呔幊痰臅r候改變狀態。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層次。



計算性能

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

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程序的技術。


  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 欧美精品一区二区三区在线 | 日日摸夜夜添夜夜添牛牛 | 国产精品久久久久一区二区 | 国产最新网站 | 最新亚洲国产 | av在线免费观看网 | 亚洲精品永久视频 | 久久另类视频 | 久草视频免费 | 欧美激情999| 91精彩在线 | 久久久久久久一区二区三区 | 夜夜夜精品视频 | fc2国产成人免费视频 | 成人永久免费视频 | 国产精品99久久久久久大便 | 欧美aaaaa一级毛片在线 | 久久久久久久久日本理论电影 | 成人免费看毛片 | 黄色免费在线电影 | 欧美国产精品一区二区 | 青青草免费观看完整版高清 | 国产资源在线观看 | 国产精品a一 | 在线a亚洲视频播放在线观看 | 露脸各种姿势啪啪的清纯美女 | 国产在线久 | 免费久久久久久 | 免费观看的毛片手机视频 | 日日操夜| 91av大片 | 一边吃奶一边插下面 | av在线免费观看播放 | 西川av在线一区二区三区 | 天堂成人国产精品一区 | 精品一区二区电影 | 中国美女一级黄色片 | 大学生一级毛片在线视频 | 国产美女自拍av | 免费欧美一级视频 | 日韩剧情片 |