Similar Threads:
1.Cannot call Dispose() while doing CreateHandle()
2.Can't call Close() while doing CreateHandle().
After some research and experimentation, I have found that the best way
to deal with the problem of closing the form while loading (at least in
my case) is to override the form's CreateHandle method. This is very
similar to overloading the OnLoad method, but it appears that the
OnLoad method is called as a "piece" of the CreateHandle function. If
you override CreateHandle (and allow it to call the base class
CreateHandle) then you can close the form *after* the base class'
CreateHandle is done. After the base class' CreateHandle is done, the
form's Load and Activate methods/events have already completed, and the
form is in a state that will allow you to close it. If necessary, keep
a member variable to track whether the form should close after
CreateHandle has completed. But in many cases, you should just be able
to use CreateHandle instead of OnLoad. In my case I had to keep a form
level variable because I wanted to close from within the Activated
event, even if the form had already been completely initialized.
3.Cannot call Close() while doing CreateHandle()
Is there a way around this error message?
Example (not what I'm actually doing but similar, this is a simple version):
Lets say you are creating some sort of calendar application you create a
form which is a MDI container, another form which is the 'events' form and a
dialog form which simply allows you to select a date with a ok and cancel
button.
Your app loads, the MDI container loads the events form. In the load of the
events form it realises that it does not have a date, so therefore it loads
the date dialog box, if you select a date and click on OK the events form
loads all the events for that particular date. However if I click the cancel
button I want the events form to close.
Regards
Gav
4.Cannot call Close() while doing CreateHandle
I get this exception when I call Me.Close on Load event of a Form. The form
producing the error is an MDI child of another form. Any ideas how I can get
over this problem please.
I have tried doing Me.Close on HandleCreated and Activated events but get
the same exception.
5.Calling Dispose instead of close, clear, ....
Hello,
I've written the following little helper function which calls Dispose on
classes which implement the idisposable interface.
Public Sub DisposeObject(ByVal DisposeAbleObject As IDisposable)
If Not DisposeAbleObject Is Nothing Then
DisposeAbleObject.Dispose()
End If
End Sub
The reason for this is to avoid ugly looking finally clauses with lots
of checking if an object ref is nothing before calling dispose on them.
For example in a try finally block in which a connection is opnened, a
transaction is started and an sqldatareader gets created which looks
like this:
try
.....
finally
if sqlconnection is nothing then
sqlconnection.close
end if
if Transaction is nothing then
Transaction.dispose
end if
if Datareader is nothing then
Datareader.close
end if
end try
i'd write this:
try
....
finally
disposeobject(sqlconnection)
disposeobject(transaction)
disposeobject(sqldatareader)
end try
a lot better looking IMO. I dont have to worry about whether the ref is
nothing or not.
Now my question is this: Is this going to cause any strange behavior?
I've tested it and it seems to work.. but im wondering if there could be
any side effects since im not calling the specific Close of the
datareader or sqlconnection, im calling the Dispose. The documentation
says there's not much difference in calling Dispose instead of Close on
a connection, but can i assume the same for any object that implements
IDisposable?
Thanks
6. DbConnection Close Throwing Exception
7. Form Events - Closing, Disposing - Removing from collections when closed
8. Does DataGridView.Dispose Call DataGridViewRow.Dispose?