Shell.Completed fires after destructor

On Windows, run the following code:

class my_shell_subclass (inherits shell)
event Completed

sub Destructor
end sub

dim a as new my_shell_subclass

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.