Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用vb.net加载程序时删除临时文件_Vb.net - Fatal编程技术网

使用vb.net加载程序时删除临时文件

使用vb.net加载程序时删除临时文件,vb.net,Vb.net,基本上,在我第一次运行程序时,它将创建临时文件并保存到文件夹中,然后程序将重新启动application.restart()。程序重新启动后,它将查找临时文件并执行一些操作。我的问题是:当我第一次运行程序时,有没有办法清除临时文件。谢谢您可能希望创建存储其创建时间的文件,如果存储时间太长(超过1分钟之前),请执行清除文件操作并重置时间。 在“我的项目>应用程序>查看应用程序事件”(ApplicationEvents.vb)中,在MyApplication类中插入以下内容: Public Sub

基本上,在我第一次运行程序时,它将创建临时文件并保存到文件夹中,然后程序将重新启动
application.restart()
。程序重新启动后,它将查找临时文件并执行一些操作。我的问题是:当我第一次运行程序时,有没有办法清除临时文件。谢谢

您可能希望创建存储其创建时间的文件,如果存储时间太长(超过1分钟之前),请执行清除文件操作并重置时间。 在“我的项目>应用程序>查看应用程序事件”(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
什么文件?根据你说的,它们在你第一次运行它之前是不存在的。毕竟,你不是这样知道这是第一次吗?没有计算您的应用程序运行了多少次。