J
Jon Brunson
Hello all, and Happy New Year!
I'm trying to delete a file after displaying it to the user, I've got
the code below so far, but it deletes the file straight away, because
the process doesn't hold onto the file, or doesn't execute quick enough
to get a hold (sometimes the executed application reports "file not
found", other times they just hang).
I can't rely on prcPreview.WaitForExit(), or prcPreview.HasExited,
because programs like PocketWord don't actually exit when you close the
file, they just SmartMinimize (ppc programmers worst enemy)
Any ideas how to delete a file after it's been viewed?
[VB.NET] ("b" is a byte array containing the contents of the file)
Dim Filename As String = Path.GetTempPath() + Me.Description + "." +
Me.FileExtention
Dim FileStream As New FileStream(Filename, FileMode.Create)
FileStream.Write(b, 0, b.Length)
FileStream.Close()
Dim prcPreview As New OpenNETCF.Diagnostics.Process
prcPreview.StartInfo.FileName = Filename
prcPreview.StartInfo.UseShellExecute = True
prcPreview.Start()
Dim bFileInUse As Boolean = True
Dim tmp As FileStream = Nothing
While bFileInUse
Try
tmp = New FileStream(Filename, FileMode.Open, FileAccess.Read,
FileShare.None)
bFileInUse = False
Catch
End Try
If Not (tmp Is Nothing) Then tmp.Close()
System.Windows.Forms.Application.DoEvents()
End While
File.Delete(Filename)
[/VB.NET]
I'm trying to delete a file after displaying it to the user, I've got
the code below so far, but it deletes the file straight away, because
the process doesn't hold onto the file, or doesn't execute quick enough
to get a hold (sometimes the executed application reports "file not
found", other times they just hang).
I can't rely on prcPreview.WaitForExit(), or prcPreview.HasExited,
because programs like PocketWord don't actually exit when you close the
file, they just SmartMinimize (ppc programmers worst enemy)
Any ideas how to delete a file after it's been viewed?
[VB.NET] ("b" is a byte array containing the contents of the file)
Dim Filename As String = Path.GetTempPath() + Me.Description + "." +
Me.FileExtention
Dim FileStream As New FileStream(Filename, FileMode.Create)
FileStream.Write(b, 0, b.Length)
FileStream.Close()
Dim prcPreview As New OpenNETCF.Diagnostics.Process
prcPreview.StartInfo.FileName = Filename
prcPreview.StartInfo.UseShellExecute = True
prcPreview.Start()
Dim bFileInUse As Boolean = True
Dim tmp As FileStream = Nothing
While bFileInUse
Try
tmp = New FileStream(Filename, FileMode.Open, FileAccess.Read,
FileShare.None)
bFileInUse = False
Catch
End Try
If Not (tmp Is Nothing) Then tmp.Close()
System.Windows.Forms.Application.DoEvents()
End While
File.Delete(Filename)
[/VB.NET]