469,328 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Self-restarting application

GTi
Does anyone have any good code for a self restarting application?
Sometimes I need to exit my application and start it again, what is the
best method of doing this in a windows form application.
The reason why I want to this is complicated, so a restart is faster
and more easier whey of doing it.

Jan 25 '06 #1
7 26204
System.Windows.Forms.Application.Restart();

Marc
Jan 25 '06 #2
Hi,

"Marc Gravell" <mg******@rm.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
System.Windows.Forms.Application.Restart();


Note that this only works in 2.0 , in 1.X there is no Restart() method
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 25 '06 #3
Hi,

"GTi" <tu****@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Does anyone have any good code for a self restarting application?
Sometimes I need to exit my application and start it again, what is the
best method of doing this in a windows form application.
The reason why I want to this is complicated, so a restart is faster
and more easier whey of doing it.


If you are using 2.0 you have a Restart method. if you are in 1.X you could
use a workaround, like spawning a new process (the spawned .exe can be
embedded in your original one) , you pass as a parameter the path to your
executable and simply exit the app, the spawned process is now still running
and it does simply wait until your original finished, and create the same
process again ( using the parameter passed before ) . It may sounds complex
but it's very easy really

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 25 '06 #4
GTi
Marc Gravell wrote:
System.Windows.Forms.Application.Restart();

Marc


Hi hi - how thoughtful by MS.

Next question.
Can I put this anywhere in my code - just where I detect when I should
restart ?
Not in any FormClosing metods ?

Jan 25 '06 #5
Technically - probably

In reality, you'd be wise to bring things to a logical conclusion first,
particularly if you have other threads playing with unmanaged resources etc;
I'm not sure how aggressive this method is in terms of aborting threads etc,
and I wouldn't want my lazy-disk-writing to get killed in the middle of a
file for an everyday reason.

Myself, I'd be paranoid and close down everything cleanly, and essentially
use this as a last line in my Main() - i.e. something like:

static void Main() {
bool restart;
using(SomeForm form = new SomeForm()) {
form.ShowDialog();
restart = form.RestartApplication;
}
if(restart)
Application.Restart();
}

You might get away with calling it elsewhere, but on your own head ;-p

Marc
Jan 25 '06 #6
GTi

Marc Gravell wrote:
Technically - probably

In reality, you'd be wise to bring things to a logical conclusion first,
particularly if you have other threads playing with unmanaged resources etc;
I'm not sure how aggressive this method is in terms of aborting threads etc,
and I wouldn't want my lazy-disk-writing to get killed in the middle of a
file for an everyday reason.

Myself, I'd be paranoid and close down everything cleanly, and essentially
use this as a last line in my Main() - i.e. something like:

static void Main() {
bool restart;
using(SomeForm form = new SomeForm()) {
form.ShowDialog();
restart = form.RestartApplication;
}
if(restart)
Application.Restart();
}

You might get away with calling it elsewhere, but on your own head ;-p

Marc


OK - It will just terminate the program where the line is.
It will not call any FormClosing metods.
Nice to know:
Then I just use a bool variables to indicate if it need a Restart at
the end of program.
Tx Marc

Jan 25 '06 #7
Hello GTi,

One of the solutions: you can build all main logic in separate DLL. Main
app is a simple controlling EXE that load dependent DLL in different ApplicationDomains.
If u need to restart app - just reload appdomain. This way, for example,
is used in SQLServer to keep in reliable.

Take into account that this solution has disadvantages - inter-appdomains
calls are expensive. You need carefully design you app in this case

G> Does anyone have any good code for a self restarting application?
G> Sometimes I need to exit my application and start it again, what is
G> the
G> best method of doing this in a windows form application.
G> The reason why I want to this is complicated, so a restart is faster
G> and more easier whey of doing it.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jan 25 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jim Jewett | last post: by
15 posts views Thread by Ralf W. Grosse-Kunstleve | last post: by
4 posts views Thread by David Coffin | last post: by
4 posts views Thread by marek.rocki | last post: by
24 posts views Thread by Peter Maas | last post: by
84 posts views Thread by braver | last post: by
13 posts views Thread by Kurda Yon | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.