473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 26680
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim Jewett | last post by:
Normally, I expect a subclass to act in a manner consistent with its Base classes. In particular, I don't expect to *lose* any functionality, unless that was the whole point of the subclass. ...
2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
18
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object):...
4
by: David Coffin | last post by:
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but...
4
by: marek.rocki | last post by:
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a...
24
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be...
84
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to...
13
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)):...
6
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.