- Form. Dispose(Boolean) Метод
- Определение
- Параметры
- Комментарии
- Примечания для тех, кто наследует этот метод
- Control. Dispose(Boolean) Метод
- Определение
- Параметры
- Комментарии
- Примечания для тех, кто наследует этот метод
- Text Box. Dispose(Boolean) Метод
- Определение
- Параметры
- Комментарии
- Примечания для тех, кто наследует этот метод
- How do I dispose a form in a WinForms application?
- 5 Answers 5
- Windows forms form dispose
- Answered by:
- Question
- Answers
Form. Dispose(Boolean) Метод
Определение
Уничтожает ресурсы (кроме памяти), используемые классом Form. Disposes of the resources (other than memory) used by the Form.
Параметры
Значение true позволяет освободить как управляемые, так и неуправляемые ресурсы; значение false освобождает только неуправляемые ресурсы. true to release both managed and unmanaged resources; false to release only unmanaged resources.
Комментарии
Этот метод вызывается открытым Dispose методом и Finalize методом. This method is called by the public Dispose method and the Finalize method. Dispose вызывает защищенный Dispose(Boolean) метод с disposing параметром, для которого задано значение true . Dispose invokes the protected Dispose(Boolean) method with the disposing parameter set to true . Finalize вызывает метод Dispose с disposing параметром, равным false . Finalize invokes Dispose with disposing set to false .
Если параметр disposing имеет значение true , то данный метод освобождает все ресурсы, занятые любыми управляемыми объектами, на которые ссылается этот объект Form. When the disposing parameter is true , this method releases all resources held by any managed objects that this Form references. Этот метод вызывает метод Dispose каждого такого объекта. This method invokes the Dispose method of each referenced object.
Dispose будет вызываться автоматически, если форма отображается с помощью Show метода. Dispose will be called automatically if the form is shown using the Show method. Если используется другой метод ShowDialog , например, или форма вообще не отображается, необходимо вызвать Dispose себя в приложении. If another method such as ShowDialog is used, or the form is never shown at all, you must call Dispose yourself within your application.
Примечания для тех, кто наследует этот метод
Метод Dispose может вызываться несколько раз другими объектами. Dispose can be called multiple times by other objects. При переопределении метода Dispose(Boolean) нужно избегать ссылок на объекты, которые были уничтожены предыдущими вызовами метода Dispose . When overriding Dispose(Boolean) , be careful not to reference objects that have been previously disposed of in an earlier call to Dispose . Дополнительные сведения о реализации см. в Dispose(Boolean) разделе Реализация метода Dispose. For more information about how to implement Dispose(Boolean) , see Implementing a Dispose Method.
Control. Dispose(Boolean) Метод
Определение
Освобождает неуправляемые ресурсы, используемые объектом Control и его дочерними элементами управления (при необходимости освобождает и управляемые ресурсы). Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources.
Параметры
Значение true позволяет освободить как управляемые, так и неуправляемые ресурсы; значение false освобождает только неуправляемые ресурсы. true to release both managed and unmanaged resources; false to release only unmanaged resources.
Комментарии
Этот метод вызывается открытым Dispose() методом и Finalize методом. Dispose() This method is called by the public Dispose() method and the Finalize method. Dispose() вызывает защищенный Dispose(Boolean) метод с disposing параметром, для которого задано значение true . invokes the protected Dispose(Boolean) method with the disposing parameter set to true . Finalize вызывает метод Dispose с disposing параметром, равным false . Finalize invokes Dispose with disposing set to false .
Если параметр disposing имеет значение true , то данный метод освобождает все ресурсы, занятые любыми управляемыми объектами, на которые ссылается этот объект Control. When the disposing parameter is true , this method releases all resources held by any managed objects that this Control references. Этот метод вызывает метод Dispose() каждого такого объекта. This method invokes the Dispose() method of each referenced object.
Примечания для тех, кто наследует этот метод
Метод Dispose может вызываться несколько раз другими объектами. Dispose can be called multiple times by other objects. При переопределении Dispose(Boolean) следует избегать ссылок на объекты, которые были удалены ранее при предыдущем вызове метода Dispose . When overriding Dispose(Boolean) be careful not to reference objects that have been previously disposed of in an earlier call to Dispose . Дополнительные сведения о реализации см. в Dispose(Boolean) разделе Реализация метода Dispose. For more information about how to implement Dispose(Boolean) , see Implementing a Dispose Method.
Text Box. Dispose(Boolean) Метод
Определение
Освобождает неуправляемые ресурсы, используемые объектом TextBox, а при необходимости освобождает также управляемые ресурсы. Releases the unmanaged resources used by the TextBox and optionally releases the managed resources.
Параметры
Значение true позволяет освободить как управляемые, так и неуправляемые ресурсы; значение false освобождает только неуправляемые ресурсы. true to release both managed and unmanaged resources; false to release only unmanaged resources.
Комментарии
Этот метод вызывается открытым Dispose методом и Finalize методом. This method is called by the public Dispose method and the Finalize method. Dispose вызывает защищенный Dispose(Boolean) метод с disposing параметром, для которого задано значение true . Dispose invokes the protected Dispose(Boolean) method with the disposing parameter set to true . Finalize вызывает метод Dispose с disposing параметром, равным false . Finalize invokes Dispose with disposing set to false .
Если параметр disposing имеет значение true , то данный метод освобождает все ресурсы, занятые любыми управляемыми объектами, на которые ссылается этот объект TextBox. When the disposing parameter is true , this method releases all resources held by any managed objects that this TextBox references. Этот метод вызывает метод Dispose каждого такого объекта. This method invokes the Dispose method of each referenced object.
Примечания для тех, кто наследует этот метод
Метод Dispose может вызываться несколько раз другими объектами. Dispose can be called multiple times by other objects. При переопределении Dispose(Boolean) следует избегать ссылок на объекты, которые были удалены ранее при предыдущем вызове метода Dispose . When overriding Dispose(Boolean) , be careful not to reference objects that have been previously disposed in an earlier call to Dispose . Дополнительные сведения о реализации см. в Dispose(Boolean) разделе Реализация метода Dispose. For more information about how to implement Dispose(Boolean) , see Implementing a Dispose Method.
How do I dispose a form in a WinForms application?
I had windows application which check if adobe acrobat installed in pc or not if it installed pdf file will display from cd if it is not installed installer window appear to setup the acrobat I did my code will but I want when pdf file run the windows form disposed I made that but this appeared:
Cannot access a disposed object. Object name: ‘Checker’.
5 Answers 5
What you are doing, is creating a form, disposing it, and then showing it.
Using explicit disposes is rarely good, but your problem is that you are trying to use the disposed object after it is disposed, so the application crashes.
Try to close the form in the Check() method, using this.Close() , and use the using statement to ensure that the form will indeed be disposed when you are done with it, like this:
In the overwhelming majority of cases, you should not call this.Dispose() in your code. By placing this call in a method called from the constructor, you’re essentially disposing the current object out from underneath yourself. The run-time detects that, and presents you with an error when you try to access your form object on the next line by calling its Show method.
In this case, if you want to close your form after the Check method finishes, you should just call its Close method:
Windows forms form dispose
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
Answers
Just because an object has been «disposed» does not mean the the object has been GC’ed, particularly with instances of WinForms.
I have observed behavior that appears that the GC seems to treat forms a little differently. Forms tend to be big complex objects, and naturally tend to take time to be GC’ed. If you open an application, which opens another form and closes it, the disposed form will sit in memory, and sit and sit and sit. It appears that the GC tends to wait before GC’ing forms until a time comes when you may not notice. In fact, most WinForms applications that open and close numerous forms will usually have one disposed form waiting to be GC’ed at all times.
Consider what it means when you close a form. It usually means you are shutting down the application, or you are about to open a new form. So when you close a form, the GC will let instance sit until you take one of those two actions. If you open a new form, then it appears the GC will go ahead and clean up the old one while you wait for the new form to open. The net result is that the user does not notice potential delays associated with completely clearing a disposed form from memory. If you close the application, then the everything gets cleaned up anyway, and once again the user does not notice potential delays associated with completely disposing of a complex instance like a form. It is as if the GC waits until you blink, and then it will GC a form instance.
I am speaking strictly about my observations of how memory grows and is eventually reclaimed as a WinForms application executes. I am not saying that this is the case, but observations seem to fit the strategy of «sneaking in» a GC cycle on a disposed form when the user will least notice.
Mark the best replies as answers. «Fooling computers since 1971.»