Problem With Application.Exit()

M

marciocamurati

Hi,

I have a problem with my application exit, I create a button that call
another form and close my application:

Private Sub closeApplication()
Dim Status As New Status
status.Show()

Application.Exit()
End Sub

At this new form I will rename the exe of the Main Form but when I
execute the:

System.IO.File.Copy(...)

But they give this error at the catch:

System.IO.IOException: The process cannot access the file "C:\......"
because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.InternalCopy(String sourceFileName, String
destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String
destFileName, Boolean overwrite)
at Atualizar.Atualizar.trocarArquivos()

Anyone know how can I fix it? Another form to exit "full" to the
application for example ?

Thanx
 
G

Guest

marciocamurati said:
Hi,

I have a problem with my application exit, I create a button that call
another form and close my application:

Private Sub closeApplication()
Dim Status As New Status
status.Show()

Application.Exit()
End Sub

At this new form I will rename the exe of the Main Form but when I
execute the:

System.IO.File.Copy(...)

But they give this error at the catch:

System.IO.IOException: The process cannot access the file "C:\......"
because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.File.InternalCopy(String sourceFileName, String
destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String
destFileName, Boolean overwrite)
at Atualizar.Atualizar.trocarArquivos()

Anyone know how can I fix it? Another form to exit "full" to the
application for example ?

Thanx

This will not do what you want. Application.exit will cease all
processing in all forms. So your exe will stay locked until your
program exits which means you can not do your copy. The way to do what
you want is to start a new process, close the exe your want to copy and
have the new process process do the copying. Which means you basically
need a seperate program to do your copying.

Chris
 
M

marciocamurati

Hi,

And how can I close that exe ? I execute anther exe that will make the
copy, in this new exe I will send a command to close the other, how can
I do this ?

Thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top