国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用以在記錄文件中寫入自定義的調試信息(主要是時間)的組件

2024-07-21 02:15:48
字體:
來源:轉載
供稿:網友
'====================================================================
'tracespy - 用以在記錄文件中寫入自定義的調試信息(開發者:林健)
'====================================================================
'
'屬性:
'       tracefilename        - 記錄文件名
'
'方法:
'   ★文本寫入方面
'       writetext            - 寫入自定義文本
'       clearalltext         - 清除所有文本
'   ★時間記錄方面
'       settimepoint         - 設置時間起點
'       gettimespanfrominit  - 詢問時間跨度(距離時間起點)
'       gettimespanfromprev  - 詢問時間跨度(距離上次詢問時間)
'
'====================================================================

public class tracespy

    '記錄文件名
    public shared tracefilename as string = "trace.txt"

    '時間起點(初始為當前時刻)
    private shared inittimepoint as long = now.ticks

    '上次詢問時間點(初始為當前時刻)
    private shared prevtimepoint as long = now.ticks

    '寫入自定義文本
    public shared sub writetext(byval str as string, optional byval showtime as boolean = false)
        tracespyfilewriter.writetext(str, showtime)
    end sub

    '清除所有文本
    public shared sub clearalltext()
        tracespyfilewriter.clearalltext()
    end sub

    '設置時間起點
    public shared sub settimepoint(optional byval note as string = "")
        inittimepoint = now.ticks
        prevtimepoint = now.ticks
        tracespyfilewriter.writetext("設置時間起點[" & note & "]。")
    end sub

    '詢問時間跨度(距離時間起點)
    public shared function gettimespanfrominit(optional byval note as string = "") as decimal
        prevtimepoint = now.ticks
        dim span as decimal
        span = cdec(prevtimepoint - inittimepoint) / 10000d
        tracespyfilewriter.writetext("詢問時間跨度[" & note & "],距離時間起點為" & span.tostring() & "毫秒。")
        return span
    end function

    '詢問時間跨度(距離上次詢問時間)
    public shared function gettimespanfromprev(optional byval note as string = "") as decimal
        dim recttimepoint as long = now.ticks
        dim span as decimal
        span = cdec(recttimepoint - prevtimepoint) / 10000d
        prevtimepoint = recttimepoint
        tracespyfilewriter.writetext("詢問時間跨度[" & note & "],距離上次詢問時間為" & span.tostring() & "毫秒。")
        return span
    end function

end class

friend class tracespyfilewriter

    private shared filewriter as system.io.streamwriter

    '向文件中寫入一個字串
    friend shared sub writetext(byval str as string, optional byval showtime as boolean = false)
        if tracespy.tracefilename = string.empty then
            exit sub
        end if
        filewriter = new system.io.streamwriter(tracespy.tracefilename, true, text.encoding.default)
        dim words as string
        words = str
        if showtime then
            words &= " @ " & now.tolongdatestring & " " & now.tolongtimestring
        end if
        filewriter.writeline(words)
        filewriter.close()
    end sub

    '清除記錄文件
    friend shared sub clearalltext()
        if tracespy.tracefilename = string.empty then
            exit sub
        end if
        filewriter = new system.io.streamwriter(tracespy.tracefilename, false, text.encoding.default)
        filewriter.write("")
        filewriter.close()
    end sub

end class菜鳥學堂:
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 濉溪县| 登封市| 青铜峡市| 武义县| 牡丹江市| 金寨县| 安国市| 谢通门县| 无极县| 兴安县| 平顶山市| 社旗县| 华亭县| 西和县| 文化| 黄陵县| 高州市| 临西县| 阳西县| 潢川县| 贺兰县| 虎林市| 达州市| 伽师县| 贵溪市| 文山县| 黔西| 陕西省| 达州市| 兰考县| 蛟河市| 横峰县| 嘉禾县| 襄城县| 修水县| 旬邑县| 革吉县| 达拉特旗| 来凤县| 临颍县| 西乌珠穆沁旗|