为什么vb .net反复在.txt中写同一行文本?

时间:2018-09-10 14:24:05

标签: .net vb.net events autocad

我创建了一个.dll文件作为AutoCAD的插件。每当事件发生时,它都会在.txt中写入有关该事件的信息。为什么它反复在.txt中写同一行文本?

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

    Public Class Class1

       <CommandMethod("AddAppEvent")>
       Public Sub AddAppEvent()

           AddHandler Application.SystemVariableChanged, AddressOf appSysVarChanged

    End Sub

    Public Sub appSysVarChanged(ByVal senderObj As Object,
                                ByVal sysVarChEvtArgs As Autodesk.AutoCAD.ApplicationServices.
                                SystemVariableChangedEventArgs)

        Dim oVal As Object = Application.GetSystemVariable(sysVarChEvtArgs.Name)

        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("C:\Users\rita.aguiar\Documents\AutoCAD plug-in\Registo de Eventos.txt", True)
        file.WriteLine("O utilizador " & Environment.UserName & " encerrou o AutoCAD às " & DateTime.Now.ToString("hh:mm, dddd, dd MMMM yyyy"))
        file.Close()

    End Sub

End Class

.txt文件中的示例输出:

这里写了4次,有时写的更多,其他的写的更少。为什么会发生这种随机事件?有人遇到过同样的问题吗?我只想写一次。

AutoCADàs01:11,segunda-feira,10 setembro 2018,实用工具rita.aguiar entrrou

AutoCADàs01:11,segunda-feira,10 setembro 2018,实用工具rita.aguiar entrrou

AutoCADàs01:11,segunda-feira,10 setembro 2018,实用工具rita.aguiar entrrou

AutoCADàs01:11,segunda-feira,10 setembro 2018,实用工具rita.aguiar entrrou

非常感谢。

1 个答案:

答案 0 :(得分:0)

我正在关注以下页面:http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer的%20Guide / index.html甚至不正确。如果我要注册autocad的关闭,则需要使用acadBeginQuit事件,而不是该页面上显示的系统变量。