基本上,我第一次运行程序时,会创建临时文件并保存到文件夹中,然后程序将重新启动application.restart()
。程序重新启动后,它将查找临时文件并执行某些操作。我的问题是:有没有办法在我第一次运行程序时清除临时文件。感谢
答案 0 :(得分:0)
您可能希望创建存储其创建时间的文件并执行清除文件并在存储时间过长(超过1分钟之前)时重置时间。 内部"我的项目> Appliation>查看应用程序事件" (ApplicationEvents.vb),在MyApplication类中,插入以下内容:
Public Sub Me_Startup(ByVal sender As Object, ByVal e As StartupEventArgs) Handles Me.Startup
Dim date As Integer() = Val(New Sysem.IO.StreamReader(System.IO.Path.Combine(
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData,
"time.txt")).ReadLine.Split({"/"c," "c,":"c}))
Dim time As New DateTime(date(0),date(1),date(2),date(3),date(4),date(5))
If time.AddMinutes(1).CompareTo(My.Computer.Clock.GmtTime) > 0 Then
My.Computer.FileSystem.DeleteDirectory(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData)
' Create your temp files
' Write them into My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
My.Computer.FileSystem.WriteAllText(System.IO.Path.Combine(
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData,
"time.txt"),My.Computer.Clock.GmtTime.ToString, False)
Application.Restart()
' It will pass onto your main code after this
End If
End Sub