Re: How to determine which process to kill ???
- From: Dino Buljubasic <dino@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 23 Sep 2005 19:17:20 GMT
OK, the question is "What to do when file is open (i.e. held by
another process, for example by process used to open it)?"
What I need to do is to close it and then delete it. How can I do
that?
On Fri, 23 Sep 2005 15:09:55 -0400, "Mike Labosh"
<mlabosh@xxxxxxxxxxx> wrote:
>1. When you create your temp files in your application, you should hold onto
>the filenames that were used, like, in a string array or something:
>
>' untested air code
>
>Private _tmpFileList As New ArrayList()
>
>Private Function createTempFile() As String
>
> Dim filename As String = _
> System.IO.Path.GetTempFileName()
>
> _tmpFileList.Add(filename)
>
>End Function
>
>Private Sub cleanupTempFiles()
>
> For Each filename As String In _tmpFileLilst
> Try
> File.Delete filename
> ' Catch -- do something here for FileNotFound or File is open
> Finally
> System.IO.Path.Delete(filename)
> End Try
> Next
>
>End Sub
>
>You could also accumulate your FileStream's or StreamReader or Writer in a
>HashTable keyed off the filenames you get from createTempFile()
>
>> for each file in temp
>> if file is open then
>> process = get process using this file
>> kill(process)
>> end if
>>
>> delete file
>> next
>
>2. That right there sounds dangerous to me. What if you accidentally kill
>some system related process or Windows Service or your AntiVirus agent(s).
>You could destabilize the system. As a rule, your application should only
>be deleting files that it created.
.
- Follow-Ups:
- Re: How to determine which process to kill ???
- From: Mike Labosh
- Re: How to determine which process to kill ???
- References:
- How to determine which process to kill ???
- From: Dino Buljubasic
- How to determine which process to kill ???
- Prev by Date: The dependency .... could not be found. DLL Hell in .NET?
- Next by Date: Re: User control
- Previous by thread: How to determine which process to kill ???
- Next by thread: Re: How to determine which process to kill ???
- Index(es):
Relevant Pages
|