Shell.Completed fires after destructor

On Windows, run the following code:

[code]
class my_shell_subclass (inherits shell)
event Completed
break

sub Destructor
break
end sub

Window1.PushButton1.Action
dim a as new my_shell_subclass
a.mode=1
a.execute"notepad"[/code]

I find that my_shell_subclass.Completed fires after that object has destructed.

Is this safe, or is code in the Completed event potentially referencing an object which may or may not still exist?

I’d say its a bug, technically notepad hasn’t completed even though it fires during destruction so the values of self in Completed are garbage once the Destructor has run.

I’d suggest popping a feedback in and code around it by keeping a in scope until you can clean up nicely.

I’d then test that solution in 2019r1 beta because I had a spectacular crash when testing this in there :slight_smile:

Perhaps the superclass Destructor is calling Shell.Close internally? Superclass destructors run after subclass destructors have returned.

Is your shell object going out of scope before it completes?

I would go with Tim’s note and make sure that you’re not leaving the scope that initialized the shell instance before it has completed. I’ve run into this before where I was launching may shells in threads.

Just for the record if anyone’s search hits this later, I found a different bug when testing this feedback://showreport?report_id=55312 (pre-release view only sorry as I found the bug originally in beta) I don’t know if they want the two issues separated or if they’ll both be fixed at the same time so it might need another bug report for the OP.