Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i use Application.Restart then it's Shuts down the application and it does not start a new instance immediately. why it is happening ? i'm using visual studio 2012 and .net 2.0. Please give me a solution. is there any other way to restart 2.0 application.

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
    End Sub

Below is the ApplicationEvents.vb file content

Namespace My
    ' The following events are available for MyApplication:
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication
    End Class
End Namespace
Sascha Lefèvre 3-Apr-15 4:16am    
Do you have a singleton-instance check in your application? (Does it check on startup whether it is already running and quits in that case?)
dipankarnalui 3-Apr-15 6:09am    
Thank u..

Reasons for restart to fail:
You have an event on form close event that prevents shutdown/restart.
You have a check that allows only a single instance of the application.

Solution: Remove the handlers and remove the single instance check before calling restart.

Good luck!
Share this answer
dipankarnalui 3-Apr-15 6:07am    
Yes sir, i had an event on form close event. I removed that code. Now it's working fine. Thank u all... Thank u so much.
E.F. Nijboer 3-Apr-15 12:06pm    
Great! Happy to help you out :-)
The reason is most probably that you have a single-instance-check in your application startup-code. Obviously the application has to restart itself while it is still running, so there's a small timeframe in which the old application is still running and the new instance is starting up, but immediately quitting because of that single-instance-check. My proposed solution: In case your application detects an already running instance of itself, let it sleep for 1-2 seconds (or longer, if your application needs time to shut down) and check again after that delay - and then only exit if the other instance is still running.
Share this answer
dipankarnalui 3-Apr-15 6:08am    
Thank u ...
Yes sir, i had an event on form close event. I removed that code. Now it's working fine. Thank u all... Thank u so much.
Share this answer
In my case, this it not the single-instance-check but the localisation of the EXE on the net.

I' working at home and my executable is on a server in my company

When i copy the executable on my computer, it works fine !!!!!

Cleraly a quetsion of delay or localisation.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900