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. Closing and recreating a form

Closing and recreating a form

Scheduled Pinned Locked Moved C#
questionperformance
28 Posts 6 Posters 0 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.
  • H Henry Minute

    I noticed the Thread.Sleep after the this.Close(), but as I could not even start to imagine what was, or was supposed to happen. I therefore very deliberately refrained from mentioning it. Now you have gone and stirred the whole thing up again! :)

    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #21

    Henry Minute wrote:

    Now you have gone and stirred the whole thing up again!

    Yeah, that's me. Always fighting against those silly Thread.Sleep(Timeout.Infinite); statements which waste an entire stack without achieving anything. Sorry for being a tad more radical; "Try commenting it out and see if everything still works..." is not really my style. ;P

    Luc Pattyn [Forum Guidelines] [My Articles]


    DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


    H 1 Reply Last reply
    0
    • L Luc Pattyn

      Henry Minute wrote:

      Now you have gone and stirred the whole thing up again!

      Yeah, that's me. Always fighting against those silly Thread.Sleep(Timeout.Infinite); statements which waste an entire stack without achieving anything. Sorry for being a tad more radical; "Try commenting it out and see if everything still works..." is not really my style. ;P

      Luc Pattyn [Forum Guidelines] [My Articles]


      DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #22

      :-O

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      L 1 Reply Last reply
      0
      • H Henry Minute

        :-O

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #23

        NP :beer:

        Luc Pattyn [Forum Guidelines] [My Articles]


        DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


        S 1 Reply Last reply
        0
        • S SimpleData

          Because I don't want to keep an extra copy of that form at the back and I need another copy of it.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #24

          Why?? If your code is written correctly, you shouldn't have to do this at all. The code should just fall back to waiting for a suported game to launch.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Why?? If your code is written correctly, you shouldn't have to do this at all. The code should just fall back to waiting for a suported game to launch.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            S Offline
            S Offline
            SimpleData
            wrote on last edited by
            #25

            I will try to make it work that way. Thanks.

            1 Reply Last reply
            0
            • L Luc Pattyn

              NP :beer:

              Luc Pattyn [Forum Guidelines] [My Articles]


              DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


              S Offline
              S Offline
              SimpleData
              wrote on last edited by
              #26

              I know that that command should not be there but it was a temporary solution and it was working in a way. This shows that this.Close(); doesn't work. I still couldn't figure out why, if it could then there would be no problem.

              1 Reply Last reply
              0
              • S SimpleData

                Hi I have a Windows form called mainwindow in my project. After it completes what it does, it closes and then recreates itself. But as I have noticed lately it recreates but doesnt't close itself. Here is my code:

                private void RestartAll()
                {
                // These are not that important, only to transfer the same properties of the form to the new form.
                depo.multipleformlocation=this.Location;
                depo.multipleform = true;
                depo.ekrangoruntusuadedi = 0;

                this.Hide();

                mainwindow _mainwindow = new mainwindow();
                _mainwindow.ShowDialog();

                this.Close();

                // Here is my temporary solution (putting old form's thread to sleep infinitely because it shouldn't keep doing what it does)
                Thread.Sleep(Timeout.Infinite);
                }

                How can I close(destroy) the old form completely and recreate that form? When I don't completely close that old form, because I do this closing and recreating process more than once my App's memory usage gets much higher. Thanks in advance.

                L Offline
                L Offline
                Lutoslaw
                wrote on last edited by
                #27

                It doesn't close because the ShowDialog method blocks the current thread. It means that the rest of the RestartAll method body is executed after a fresh copy of your mainwindow is closed. Switch to Show() instead. I think that you can also move this.Close above _mainwindow.Show().

                Greetings - Jacek Gajek

                S 1 Reply Last reply
                0
                • L Lutoslaw

                  It doesn't close because the ShowDialog method blocks the current thread. It means that the rest of the RestartAll method body is executed after a fresh copy of your mainwindow is closed. Switch to Show() instead. I think that you can also move this.Close above _mainwindow.Show().

                  Greetings - Jacek Gajek

                  S Offline
                  S Offline
                  SimpleData
                  wrote on last edited by
                  #28

                  If I do it that way, then no new mainwindow appears.

                  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