Run Code/Fire Event After First Event Finishes
-
I have a form with an ActiveX control on it. When the disconnect event of the OCX runs, I want to close the form. The problem is, if I call the close command from within the disconnect event, I get an access violation as the form/control is disposed of when the OCX event finishes up.
OCX Disconnect Event
{
Custom EventHandler for OCX Disconnect Event
{
Clean up all connections and close form
{
Form Close Event
{
Form is closed and all controls are disposed of
{
}
}
}
}
Exception thrown as the parent form no longer exists
}I just need to make the Clean up all connections and close form function run after OCX Disconnect Event, but I don't know how or if its possible. Any help or work arounds would be appreciated. Currently, my only work around is basically to leave the parent form open and have the user close it.
-
I have a form with an ActiveX control on it. When the disconnect event of the OCX runs, I want to close the form. The problem is, if I call the close command from within the disconnect event, I get an access violation as the form/control is disposed of when the OCX event finishes up.
OCX Disconnect Event
{
Custom EventHandler for OCX Disconnect Event
{
Clean up all connections and close form
{
Form Close Event
{
Form is closed and all controls are disposed of
{
}
}
}
}
Exception thrown as the parent form no longer exists
}I just need to make the Clean up all connections and close form function run after OCX Disconnect Event, but I don't know how or if its possible. Any help or work arounds would be appreciated. Currently, my only work around is basically to leave the parent form open and have the user close it.
I understand your question like this: the OCX has to be disconnected at some time; the Form should be closed when the OCX disconnect has finished. I know of no perfect solution, this is what I would do: - when you want to disconnect, close the Form; - in FormClosing event, tell the OCX to disconnect and wait; if there is no way to get feedback on the disconnect, the wait would be for a fixed time (e.g. 1 sec); if there is a way, a timeout mechanism should also be provided (it would be unacceptable for a Form not to be closing at all). Hope this helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I understand your question like this: the OCX has to be disconnected at some time; the Form should be closed when the OCX disconnect has finished. I know of no perfect solution, this is what I would do: - when you want to disconnect, close the Form; - in FormClosing event, tell the OCX to disconnect and wait; if there is no way to get feedback on the disconnect, the wait would be for a fixed time (e.g. 1 sec); if there is a way, a timeout mechanism should also be provided (it would be unacceptable for a Form not to be closing at all). Hope this helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.
-
Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.
Hmm. I guess the event you really want isn't available, so I'd look for a polling scheme then; have a thread or timer periodically try and figure out whether the OCX is still connected, if not, close the Form (or pop up a dialog). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.
-
As an alternative, albeit a messy one; add a timer component to the form, start it from the disconnect, and have the
Tick
event disable the sender-timer and close the form.I are Troll :suss:
The Timer method worked great. Thanks for helping me find a work around on this.
-
The Timer method worked great. Thanks for helping me find a work around on this.