国产探花免费观看_亚洲丰满少妇自慰呻吟_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菜鳥學堂:
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湖南省| 大庆市| 响水县| 黔西| 石屏县| 丹阳市| 霍林郭勒市| 遵化市| 通海县| 新平| 汕尾市| 五河县| 嘉禾县| 商都县| 汝州市| 全椒县| 太仆寺旗| 临沭县| 江油市| 璧山县| 鲁甸县| 锦州市| 贵德县| 三明市| 尼玛县| 太仆寺旗| 舞阳县| 周口市| 汝州市| 米林县| 湾仔区| 抚宁县| 昭通市| 日照市| 灯塔市| 济源市| 桂阳县| 光山县| 南昌市| 陆良县| 绥江县|