how to restart console application?
-
i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint? thanks :)
buchstaben wrote:
i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint?
There isn't one. You'll have to write it yourself. All restart does is to start a new instance of the application with the same set of conditions as the original was started within then shut down the current instance.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
-
i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint? thanks :)
Call Main again - but don't forget to include an exit condition somewhere otherwise you'll end up in an infinite loop.
Deja View - the feeling that you've seen this post before.
-
Call Main again - but don't forget to include an exit condition somewhere otherwise you'll end up in an infinite loop.
Deja View - the feeling that you've seen this post before.
calling main again would result in two running applications. there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
-
buchstaben wrote:
i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint?
There isn't one. You'll have to write it yourself. All restart does is to start a new instance of the application with the same set of conditions as the original was started within then shut down the current instance.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
hm..in this case, the "new" instance is startet before the old is killed. i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
-
calling main again would result in two running applications. there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
buchstaben wrote:
calling main again would result in two running applications.
No it wouldn't. It would be the same application but the starting point is called for a second time.
buchstaben wrote:
there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
I'm not sure you are using the word process correctly here. Do you mean process as in a ancillary application (which would be the correct use of the word) or process as in another thread? If you mean process as in other processes (ancillary applications) then just kill the processes. If you mean process as in another thread then kill the threads.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
-
hm..in this case, the "new" instance is startet before the old is killed. i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
buchstaben wrote:
hm..in this case, the "new" instance is startet before the old is killed.
Yes - Which is also how
Application.Restart
works too. (I naturally assume that you know this already)buchstaben wrote:
i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
Why? You were happy to use
Application.Restart
if it were available to you.Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
-
calling main again would result in two running applications. there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
buchstaben wrote:
calling main again would result in two running applications.
No it wouldn't. You're not actually going to create a new process here - why do you think Main would behave differently to any other method, none of which results in a new process?
buchstaben wrote:
there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
This sounds like you are getting a bit confused architecturally. Don't restart the application - just kill the threads (be aware that this is really frowned upon though).
Deja View - the feeling that you've seen this post before.
-
buchstaben wrote:
calling main again would result in two running applications.
No it wouldn't. It would be the same application but the starting point is called for a second time.
buchstaben wrote:
there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
I'm not sure you are using the word process correctly here. Do you mean process as in a ancillary application (which would be the correct use of the word) or process as in another thread? If you mean process as in other processes (ancillary applications) then just kill the processes. If you mean process as in another thread then kill the threads.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
i meant process in the thread context. so i'm gonna kill all running background threads and return to main. thanks.
-
buchstaben wrote:
hm..in this case, the "new" instance is startet before the old is killed.
Yes - Which is also how
Application.Restart
works too. (I naturally assume that you know this already)buchstaben wrote:
i'm not sure right now if this can be a problem, but i'd prefer to avoid this..
Why? You were happy to use
Application.Restart
if it were available to you.Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |
Colin Angus Mackay wrote:
Why? You were happy to use Application.Restart if it were available to you.
I were happy because I didn't know the behaviour ;) However, it works now.
-
buchstaben wrote:
calling main again would result in two running applications.
No it wouldn't. You're not actually going to create a new process here - why do you think Main would behave differently to any other method, none of which results in a new process?
buchstaben wrote:
there are some background activities running in my app. in the main thread somewhere i'm waiting until all backgound processes finished. but if a certain time elapsed, i dont want to wait anymore and restart application, since there might be a hangup in any background process.
This sounds like you are getting a bit confused architecturally. Don't restart the application - just kill the threads (be aware that this is really frowned upon though).
Deja View - the feeling that you've seen this post before.
Pete O'Hanlon wrote:
This sounds like you are getting a bit confused architecturally. Don't restart the application - just kill the threads (be aware that this is really frowned upon though).
just killing the threads wouldn't help, since i must ensure each background thread runs every main run. a main run simply covers invoking all registered background threads, starting a timer and wait for the timer's and threads' ready-events. if both, timer and all threads are ready, start a new main run. if timer is ready since x seconds, (assuming non-expected exception) the app should ignore the background threads' states and stop current main run. now all background threads have to be killed and invoked again. that's actually what my goal is. architecturally this should be ok, shouldn't?