??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????? Han Rui
?
When Dafu's instance of the Form1 form was hidden, the example of the FORM2 form was closed, so I lost the manual control of the main thread, the process could not be closed. I have to use Ctrl Alt DEL to call up the system process manager to force the process. In order to avoid looking up, I have to look at the smile of Da Li.
Yes, I just want to intercept the message that the Form2 instance is turned off, can you adjust the hidden primary threaded window? Re-dash the Closing method in the base class event: Base Class Event:
Private sub form2_closing (Byval e AS _BYVAL E AS _
System.componentmodel.canceleventargs) Handles mybase.closing
??????? frm1.show ()
??? End Sub
Ha, it is very convenient, after I close the form of the FORM2 form, the FRM1 hidden will appear again.
"Well," Da Li finally spoke, "You click on the Button1 on the Form1 form."
My vest is cold, and I feel that Da Li is waiting for this time. I am helpless, I can only do it as he said. Sure enough, pop up an error window:
"You closed the example of the FORM2, but also ended the survival of this object," Da Li seems to be a long time, "this is what the 'unable to access Form2 in the error prompt." Object '. When we turn off a window, a termination response will be issued, and the window object, the FRM2 defined above, feed the termination queue, the garbage collector of the public language running, tracks the survival of this object This object base class is called, such as the Dispose method of Form2, used to destroy the object and collect resources. So ... "
"So I just judge whether FRM2 is destroyed, if destroyed, I will construct an instance not?" I suddenly realized.
Lari Li's first smile and nodded: "You can judge it with frm2.isdisposed."
I wrote the gods:
Private sub button1_click (byval sender as system.Object, _
Byval e as system.eventargs) Handles Button1.click
??????? If frm2 is nothing or frm2.isdisposed then? 'Determined whether the object is destroyed
??????????? frm2 = new form2 ()
??????? endiff
??????? me.hide ()
??????? frm2.show ()
??? End Sub
This is more perfect, and the switch between the two forms will not have so many other questions. I turned, I saw that Da Li had already sat in the chair.
"You tell, the process of creation and destruction of the form of VB.NET."
I sorted a mess, I gave a sigh of breath, and I started to say: "A form class, such as the Form1 class, by calling its base class, is the new method of the Form class to create an instance, the Dispose method to destroy the instance."
"Yes." Big Li, talking, while clicking on the "Windows Form Designer Generator Generation of the Windows Form Designer":
?? public subnewatch () ??????? mybase.new ()
??????? 'This call is required for the Windows Form Designer.
??????? InitializeComponent ()
??????? 'Add any initialization after INITIALIZECOMPONENT () call
??? End Sub
??? 'Form rewriting disposal to clean the component list.
??? protected overloads overrides sub dispose (byval disposing as boolean)
??????? if disposing kil
??????????? if not (Components Is Nothing) THEN
??????????????? company.dispose ()
??????????? end if
??????? endiff
??? ???? mybase.dispose (Disposing)
??? End Sub
Big Li began to explain: "MyBase keyword behavior is similar to object variables for the base class of the current instance of the category. MyBase is often used to access the base class members who have been rewritten or hidden in the derived class. In this code, MyBase refers to the system.windows.forms.form class. The New method used when constructed the object is explicitly called, but there is nothing to explain. But the designer method is worth mentioning. "
He looked at me and continued: "The form.dispose method is to rewrite the CONTROL.Dispose method, then what is the meaning of the Control.Dispose method? Its role is: Release the unmanaged by Control Resources, you can also release managed resources again. When DISPOSIING in its parameters are released, the managed resource and unmanaged resources are released; if False releases the non-hosting resource. The Disposing of the Form class is True. Automatically call when the form is turned off Dispose's functionality is to benefit from the .NET's public language runtime, the runault library automatically processes object layout and manages the object's reference, and release them when the object is no longer used. The object of its living period is managed in this way called Managed data. Automatic memory management eliminates memory leaks and other common programming errors. Any type of Dispose method should release all of its resources it has. It should also release all of its parent type Dispose methods to release its base type owned Resources. The DISPOSE method of the parent type should release all the resources it own and also call the DISPOSE method of its parent type, thereby propagating this mode throughout the primary type hierarchy. To ensure that the resource is always properly cleaned, the Dispose method should be Multiple secure calls without causing any exceptions. "
"However, if the system problem or application calls up, what should I do if I don't call Dispose?" I remembered what, asked.
"If the Dispose also releases unclear or no call, the system's garbage collector will call the object's Finalize method to clear. Because the Finalize method is greatly damaged, we will not use it to clean up with it. "Da Li explained slightly.
I finally remembered an important issue: "If the global variables defined in the module are handled, will there be a security problem because the access range is too large?"
"Of course, we can try other solutions." Da Li always has a preparation.
-------------------------------------------------- -------------
Disclaimer: The right to copyright and interpretation of this article belongs to Han Rui, if you need to reprint, please keep your full content and this statement.
QQ: 18349592
E-mail: Henry7685@hotmail.com
Please visit my column:
Http: // 呜呜 .9 Publishing House .NET / DEVELOP / Author / Net Author / Latitude /