Revit Crash when closing after using WPF application - my fix

Revit Crash when closing after using WPF application - my fix

Anonymous
Not applicable
594 Views
4 Replies
Message 1 of 5

Revit Crash when closing after using WPF application - my fix

Anonymous
Not applicable

Dear forum users,

 

I spent too much time finding a solution not to share it with you.

My problem:

Revit crash after closing the active document. This happened only after I opened and closed my WPF application.

Otherwise, the application works perfectly.

 

Cause:

I used WPF commands binded to buttons, with the CanExecute checking if the Revit selection was empty or not.

 

Don't do that in your commands:

        public bool CanExecute(object parameter)
        {
            //if (_vm.Uidoc.Selection.GetElementIds().Count == 0)
            //{
            //    return false;
            //}
            return true;
        }

 

I thought it was pretty cool.And it worked, but made Revit crash when the document was closed.
Anyone have a solution to get the same result without crashing Revit?

 

Anyway, I hope I can help someone find that solution faster than I could.

 

Best Regards,

François Robberts

0 Likes
595 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

The title is a bit misleading should have been: "Revit crash when closing active view whilst using WPF command bindings"

 

I don't understand the wider context as to why you are trying this. Trying to use out of date / out of context objects is likely the cause (things long gone on unmanaged side). There have been a few threads regarding detecting selection changed for modeless windows if that helps?

 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

I wanted to make sure at least one item was selected before I could press the button, just for convience sake.

I will indeed check threads regarding detecting selection changed.

Sorry about the title.


Thank you

0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor

Sorry it is just something that caught my attention since WPF is probably the only thing I've been using in the last decade. I did get crashes in the past but related to other things such as showing window after a long running Revit process (in the same context i.e. at end of print process).

 

Detecting selection changed usually boils down to making use of idling event or using the undocumented AdWindows to detect something inherently happening on the interface when selection changes.

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

No thank you for the feedback! This is the whole point of posting here 🙂

I now have a direction to look at.

0 Likes