I've got an interesting problem. I have a .net 2.0 app that goes off to a server to get a file and unzip it locally. This process is threaded. It's possible that during the first run through the process the end-user may need to stop the original process and go get a different file.
So, I abort the initial thread and start over. The issue? (Glad you asked) Seems that one or more files (the zip and possibly files from within the zip file, depending on how far along the initial process is) will not delete (File.Delete(path) as these files are in use my another process.
Exact error:
Description: The process cannot access the file 'c:\TestExtract\75872-01-1.ado' because it is being used by another process.
The code that is pulling the file from the zip is here:
--- BEGIN CODE CHUNK --------
If (sFileName <> String.Empty) Then
Dim StreamWriter As FileStream = File.Create(sDirectory & theEntry.Name)
Dim Size As Integer = 2048
Dim data(2048) As Byte
While (True)
Size = stmZipFile.Read(data, 0, data.Length)
If (Size > 0) Then
StreamWriter.Write(data, 0, Size)
Else
Exit While
End If
End While
StreamWriter.Close()
End If
--- END OF CODE CHUNK --------
Ive tried watching for the thread's abort request in that loop, but it never gets it. So I can't close the stream (arg)
I've looked to see if I can get the handle of the process that is using the file so I can kill the process and then the file... but so far no luck. I'm heading home now, but I'll check back in a few hours (it's 5pm est)
Yes. Why not? IoT Enterprise is binary-compatible with non-IoT SKUs, meaning it has everything that a "standard" SKU has from a software perspective. Remember, it's just a name that Microsoft uses to designate a usage case, it doesn't mean it's a different Windows per se.
https://en.wikipedia.org/wiki/Windows_IoT#Enterprise
If had the money, I would have at least 3 or 4 computers to play with. But I only have one and I work with it. So, I need something that I'm sure it will work, not only for me, but for my job too. Linux ain't it.
Question
James Rose
Ok gang,
I've got an interesting problem. I have a .net 2.0 app that goes off to a server to get a file and unzip it locally. This process is threaded. It's possible that during the first run through the process the end-user may need to stop the original process and go get a different file.
So, I abort the initial thread and start over. The issue? (Glad you asked) Seems that one or more files (the zip and possibly files from within the zip file, depending on how far along the initial process is) will not delete (File.Delete(path) as these files are in use my another process.
Exact error:
Description: The process cannot access the file 'c:\TestExtract\75872-01-1.ado' because it is being used by another process.
The code that is pulling the file from the zip is here:
--- BEGIN CODE CHUNK --------
If (sFileName <> String.Empty) Then
Dim StreamWriter As FileStream = File.Create(sDirectory & theEntry.Name)
Dim Size As Integer = 2048
Dim data(2048) As Byte
While (True)
Size = stmZipFile.Read(data, 0, data.Length)
If (Size > 0) Then
StreamWriter.Write(data, 0, Size)
Else
Exit While
End If
End While
StreamWriter.Close()
End If
--- END OF CODE CHUNK --------
Ive tried watching for the thread's abort request in that loop, but it never gets it. So I can't close the stream (arg)
I've looked to see if I can get the handle of the process that is using the file so I can kill the process and then the file... but so far no luck. I'm heading home now, but I'll check back in a few hours (it's 5pm est)
Thanks for any ideas.
Link to comment
https://www.neowin.net/forum/topic/578013-vbnet-delete-file-in-process/Share on other sites
4 answers to this question
Recommended Posts