Form.ShowDialog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jetean
    New Member
    • Feb 2008
    • 33

    #1

    Form.ShowDialog

    Hi:
    I search through this forums and google around about this Form.ShowDialog ():
    I'm unable to make the event at Child Form stop running and It looks like the child Form is still "Alive":

    Here:
    At Form1
    Code:
            private void button1_Click(object sender, EventArgs e)
            {
    
                Form2 frm2 =new form2();
                frm2.ShowDialog();
    At Form 2

    Code:
      private void button1_Click(object sender, EventArgs e)
            {
                this.Dispose();
             
            }
    Very Simple? But when I check the Output Window, Form2 is still performing Console.Writeli ne

    Thanks
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    try
    this.close();

    instead of
    this.dispose();

    Generally speaking, you don't call .dispose(). It gets called automatically when the object goes out of scope and the resources are to be recovered for the application. You can't dispose of it if it is still in existence. It still exists until you close it, and all references to it go out of scope.

    Comment

    • Jetean
      New Member
      • Feb 2008
      • 33

      #3
      Originally posted by tlhintoq
      try
      this.close();

      instead of
      this.dispose();

      Generally speaking, you don't call .dispose(). It gets called automatically when the object goes out of scope and the resources are to be recovered for the application. You can't dispose of it if it is still in existence. It still exists until you close it, and all references to it go out of scope.
      It is still the same. I tried both before I posted this. Have you tried At Form2:
      create new timer (System.Timer) and performed counting and output with Console.Writeli ne, then close Form2 (Open Form2 from Form 1 either with Form2.ShowDialo g or Show()), the Timer event is still working even Form2 is disposed! (I thought object after disposed should be collected by GC and vanishded since it already out of scope?)

      Now if replace System.Timer with Timer (from toolbox) , ha ha, there is a difference! The Console.Writeli ne stop running (well is Form2 actually disposed???)

      What If I have event that will fired and Form2 subscribe from the Form1 Event?
      (I tested it, Form 2 with console writeline at the method that subscribed to Form1 is still running even Form2 is Closed or Disposed !!!)

      Is this what described as :"Memory Leaked"?


      How can make sure Form2 is really disposed and no more working "in the background" ....

      PS: VB6 have a method call unloading.

      Thanks

      Comment

      Working...