Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to restart console application?

how to restart console application?

Scheduled Pinned Locked Moved C#
tutorialquestion
11 Posts 3 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buchstaben
    wrote on last edited by
    #1

    i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint? thanks :)

    C P 2 Replies Last reply
    0
    • B buchstaben

      i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint? thanks :)

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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 |

      B 1 Reply Last reply
      0
      • B buchstaben

        i need the equivalent to System.Windows.Forms.Application.Restart() for console app. any hint? thanks :)

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        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.

        My blog | My articles

        B 1 Reply Last reply
        0
        • P Pete OHanlon

          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.

          My blog | My articles

          B Offline
          B Offline
          buchstaben
          wrote on last edited by
          #4

          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.

          C P 2 Replies Last reply
          0
          • C Colin Angus Mackay

            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 |

            B Offline
            B Offline
            buchstaben
            wrote on last edited by
            #5

            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..

            C 1 Reply Last reply
            0
            • B buchstaben

              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.

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              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 |

              B 1 Reply Last reply
              0
              • B buchstaben

                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..

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                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 |

                B 1 Reply Last reply
                0
                • B buchstaben

                  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.

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  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.

                  My blog | My articles

                  B 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    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 |

                    B Offline
                    B Offline
                    buchstaben
                    wrote on last edited by
                    #9

                    i meant process in the thread context. so i'm gonna kill all running background threads and return to main. thanks.

                    1 Reply Last reply
                    0
                    • C Colin Angus Mackay

                      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 |

                      B Offline
                      B Offline
                      buchstaben
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • P Pete OHanlon

                        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.

                        My blog | My articles

                        B Offline
                        B Offline
                        buchstaben
                        wrote on last edited by
                        #11

                        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?

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups