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. Application shuts down and not just the form

Application shuts down and not just the form

Scheduled Pinned Locked Moved C#
helpquestion
14 Posts 4 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.
  • S Offline
    S Offline
    Saamir
    wrote on last edited by
    #1

    Hi guys, This might be a broad question for help but I request any suggestions. I have an application in which upon login I hide it with the use of a notify icon. As transactions happen, my hidden app calls another form which works fine for the most part but sometimes the form that I call, upon closing it shuts down my hidden application as well. Is there a way for me to troubleshoot this or avoid this issue. Please advice. Thanks in advance

    Sameer

    V D 2 Replies Last reply
    0
    • S Saamir

      Hi guys, This might be a broad question for help but I request any suggestions. I have an application in which upon login I hide it with the use of a notify icon. As transactions happen, my hidden app calls another form which works fine for the most part but sometimes the form that I call, upon closing it shuts down my hidden application as well. Is there a way for me to troubleshoot this or avoid this issue. Please advice. Thanks in advance

      Sameer

      V Offline
      V Offline
      vlinker
      wrote on last edited by
      #2

      Can you show me code which close form

      P S 2 Replies Last reply
      0
      • V vlinker

        Can you show me code which close form

        P Offline
        P Offline
        praveenvkumarv
        wrote on last edited by
        #3

        the form which you want to close. the deactivated() event of that form include code this.close();

        S 1 Reply Last reply
        0
        • V vlinker

          Can you show me code which close form

          S Offline
          S Offline
          Saamir
          wrote on last edited by
          #4

          it's a huge piece of code so I will try and explain it. The form that I am trying to close that is closing my application is: 1. visible=false 2. the part where I call this.close(), I am sending a print job upon which I call this.close(). So, when I call the close, my form is still invisible. Sameer

          Sameer

          V 1 Reply Last reply
          0
          • P praveenvkumarv

            the form which you want to close. the deactivated() event of that form include code this.close();

            S Offline
            S Offline
            Saamir
            wrote on last edited by
            #5

            I don't understand. What do you mean by deactivated event. Instead of using this.close() do you think I should use Form.ActiveForm.Close();

            Sameer

            1 Reply Last reply
            0
            • S Saamir

              it's a huge piece of code so I will try and explain it. The form that I am trying to close that is closing my application is: 1. visible=false 2. the part where I call this.close(), I am sending a print job upon which I call this.close(). So, when I call the close, my form is still invisible. Sameer

              Sameer

              V Offline
              V Offline
              vlinker
              wrote on last edited by
              #6

              How you create this form?

              S 1 Reply Last reply
              0
              • V vlinker

                How you create this form?

                S Offline
                S Offline
                Saamir
                wrote on last edited by
                #7

                What do you mean?

                Sameer

                V 1 Reply Last reply
                0
                • S Saamir

                  What do you mean?

                  Sameer

                  V Offline
                  V Offline
                  vlinker
                  wrote on last edited by
                  #8

                  Please,Show me code show/hide form. Maybe

                  this.close

                  replace by

                  visible=false

                  S 1 Reply Last reply
                  0
                  • V vlinker

                    Please,Show me code show/hide form. Maybe

                    this.close

                    replace by

                    visible=false

                    S Offline
                    S Offline
                    Saamir
                    wrote on last edited by
                    #9

                    here is some code here is my hide application code: public void HideApp() { //this.WindowState = FormWindowState.Minimized; Hide(); } This is when I open the new form which upon closing is shutting down the whole application. this.timer1.Enabled=false; try { Payment frm = new Payment(m_pDBCnn, m_pDBUserId, m_pDBPassword, EmpId, TermNum, SiteId, TrnNum, LogId, SystemConfig); if (frm.ShowDialog(this) == DialogResult.Cancel) { Status = frm.Status; if (Status == 1) { this.timer1.Enabled = true; this.PopulateInvoices(); } } } catch (Exception ex) { MessageBox.Show("Error in payment, contact Administrator\n" + ex.Message, "SelecSoftware POS™", MessageBoxButtons.OK, MessageBoxIcon.Error); }

                    Sameer

                    1 Reply Last reply
                    0
                    • S Saamir

                      Hi guys, This might be a broad question for help but I request any suggestions. I have an application in which upon login I hide it with the use of a notify icon. As transactions happen, my hidden app calls another form which works fine for the most part but sometimes the form that I call, upon closing it shuts down my hidden application as well. Is there a way for me to troubleshoot this or avoid this issue. Please advice. Thanks in advance

                      Sameer

                      D Offline
                      D Offline
                      DiscoJimmy
                      wrote on last edited by
                      #10

                      The general pattern for this is to have the main form - the one that is hiding in the system tray - own a reference to the other form. Then when that child form needs to close, either call this.Close() from inside the child form, or have it call an event. The parent form(the one that's hiding) will subscribe to that event, and call Dispose() on it's reference to the child form. That should kill the child form while leaving the parent form running in the system tray. Just don't call Application.Exit() or it will kill all your forms.

                      S 1 Reply Last reply
                      0
                      • D DiscoJimmy

                        The general pattern for this is to have the main form - the one that is hiding in the system tray - own a reference to the other form. Then when that child form needs to close, either call this.Close() from inside the child form, or have it call an event. The parent form(the one that's hiding) will subscribe to that event, and call Dispose() on it's reference to the child form. That should kill the child form while leaving the parent form running in the system tray. Just don't call Application.Exit() or it will kill all your forms.

                        S Offline
                        S Offline
                        Saamir
                        wrote on last edited by
                        #11

                        Do I do this by using delegates?

                        Sameer

                        D 1 Reply Last reply
                        0
                        • S Saamir

                          Do I do this by using delegates?

                          Sameer

                          D Offline
                          D Offline
                          DiscoJimmy
                          wrote on last edited by
                          #12

                          If you mean the second method with the events, then yes and no. Yes, events use delegates behind the scenes, but no you don't have to actually declare any delegates yourself. Just declare an event on the child form using the basic EventHandler class, and then inside the parent form you create an instance of the child form, and subscribe to the event with the += syntax. The parent form then provides an event handler(just like button1_Click) and inside that method you can call Dispose() on the child form. Or set it to null, it's basically the same thing. on the child form: public event EventHandler CloseMe; on the parent form: ChildForm myChildForm = new ChildForm(); myChildForm.CloseMe += new EventHandler(CloseMethod); and make sure the child form calls that event when it wants to be shut down. Of course depending on what you're doing, it would probably be easier to just call this.Close() inside the child form, but then the parent form wouldn't know about it. I haven't used these inline code blocks before, so hopefully that formats ok.

                          S 1 Reply Last reply
                          0
                          • D DiscoJimmy

                            If you mean the second method with the events, then yes and no. Yes, events use delegates behind the scenes, but no you don't have to actually declare any delegates yourself. Just declare an event on the child form using the basic EventHandler class, and then inside the parent form you create an instance of the child form, and subscribe to the event with the += syntax. The parent form then provides an event handler(just like button1_Click) and inside that method you can call Dispose() on the child form. Or set it to null, it's basically the same thing. on the child form: public event EventHandler CloseMe; on the parent form: ChildForm myChildForm = new ChildForm(); myChildForm.CloseMe += new EventHandler(CloseMethod); and make sure the child form calls that event when it wants to be shut down. Of course depending on what you're doing, it would probably be easier to just call this.Close() inside the child form, but then the parent form wouldn't know about it. I haven't used these inline code blocks before, so hopefully that formats ok.

                            S Offline
                            S Offline
                            Saamir
                            wrote on last edited by
                            #13

                            I am using this.close() in the child form and I believe that is what is shutting down my application. What I have noticed is it shutsdown around the time I send a print job. I have this.close() right after I send the print job. I am using the same namespace in my child and parent form even though they are a part of a different project, would that cause the issue?

                            Sameer

                            D 1 Reply Last reply
                            0
                            • S Saamir

                              I am using this.close() in the child form and I believe that is what is shutting down my application. What I have noticed is it shutsdown around the time I send a print job. I have this.close() right after I send the print job. I am using the same namespace in my child and parent form even though they are a part of a different project, would that cause the issue?

                              Sameer

                              D Offline
                              D Offline
                              DiscoJimmy
                              wrote on last edited by
                              #14

                              That i'm not sure about. Maybe try handling the Closing event on the parent form, and then put in a breakpoint and look at the call stack. it'd be interesting to see what methods were called right before the main form closes.

                              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