-4

Been trying to make my program restart from a button click in the program and codes like "restart()" and "recreate()" dont exist. Any idea what code would work?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
kbluue
  • 369
  • 1
  • 5
  • 20
  • 3
    I’m really sorry if I’m incorrect to ask this, but: are you serious? It’s just the combination of C# and Java tags and “trying random codes” that makes me think otherwise. – Ry- May 18 '14 at 06:17
  • i dont get you. AT ALL! – kbluue May 18 '14 at 06:18
  • 2
    If winforms app: `Application.Restart` – Sriram Sakthivel May 18 '14 at 06:20
  • 1
    @user3577705 minitech was referring to the fact that you are treating programming as if it was magic. Don't. – The Paramagnetic Croissant May 18 '14 at 06:20
  • @minitech I hope I don't even need to flag this one for you... – The Paramagnetic Croissant May 18 '14 at 06:20
  • You are likely looking for something else... But your precise question - use `Process.Start` with path to executable (both parts are easily searchable on SO/MSDN). – Alexei Levenkov May 18 '14 at 06:20
  • i mean i tried restart and it aint working. – kbluue May 18 '14 at 06:22
  • Are you using Windows Forms? – Ry- May 18 '14 at 06:22
  • @SriramSakthivel It doesn't even have to be a Windows Forms app. He can import the library and use that method in a WPF app if he/she chooses to do so. – B.K. May 18 '14 at 06:31
  • so i guess someone can tell me how to go about with the library import. and yes its a window form. – kbluue May 18 '14 at 06:34
  • @kbluue If it's a Windows Forms app, you don't have to import anything -- you already have it. Just see my answer. Otherwise, simply right click `References` under `Solution Explorer` and choose `Add Reference...`. Scroll down until you see `System.Windows.Forms` and check it. Then click `OK`. That's it. – B.K. May 18 '14 at 06:37
  • @B.K thanks man. it totally worked – kbluue May 18 '14 at 06:42
  • @B.K it goes off and comes back on. so i was thinking, for user experience, if i could store the initial state so that the restart command would just repaint. but i have a lot of items and i cant treat my checkboxs in an array. an ideas? – kbluue May 18 '14 at 06:54
  • @kbluue http://stackoverflow.com/a/7522298/2006048 For a lot of my applications I use settings files and SQLite databases. To each is own and it all depends on what you do and what environment you're developing for. – B.K. May 18 '14 at 06:55

1 Answers1

1

You can probably do something like this:

System.Windows.Forms.Application.Restart();  // it does exist...
Application.Current.Shutdown(); // If you are using WPF, otherwise see below...

Use Application.Exit() or this.Close() for the second line in a Windows Forms App.

B.K.
  • 9,982
  • 10
  • 73
  • 105