ExternalEventHandler not fired

ExternalEventHandler not fired

luc.vallotP8MJ4
Contributor Contributor
1,142 Views
6 Replies
Message 1 of 7

ExternalEventHandler not fired

luc.vallotP8MJ4
Contributor
Contributor

hi,

 

Inside our plugin, we have a wpf dialog, with a button who use an externalevent to open a rvt file (using openandactivatedocument function) (and close the window itself)

the process work fine in most revit sessions, but sometimes in some Pc's, the event is correctly raised and the execute function is not executed. Frequently (but not systematically) then this occurs, the execution can'be fired until closing and reopening revit

 

I have checked : then the problem occurs, the external event is pending and the raise function result as accepted

there are no exceptions errors during the execution, no revit errors or warnings

 

The problem rarely happens with revit 2018 but more frequently with revit 2019 or 2020

 
as the problem appair sometimes and to all PC's, I can't send a reproductible sample
 
How can I solve this , is it a trace in the revit log to analyze the cause ?

Luc

 

 

 

 

0 Likes
1,143 Views
6 Replies
Replies (6)
Message 2 of 7

jjesusdelpino
Advocate
Advocate

Hi luc,

 

Im not an expert but I have been dealing with external events last days. Its a fact that you cant controll exactly the time of execution when you trigger external events (even more considering that you are trying to open a document from outside API context). Anyway, there is a couple of things that you can try in your case.

 

1 - Try to trigger the external event immediately by giving Revit the focus:

https://thebuildingcoder.typepad.com/blog/2013/12/triggering-immediate-external-event-execute.html

 

Or better 2 - Use the "new" library to wrap external events asynchronously from Kennan Chen that Jeremy again refers in this post: https://thebuildingcoder.typepad.com/blog/2020/03/another-async-await-rex-and-structural-analysis-sd...

 

I hope this helps, regards.

0 Likes
Message 3 of 7

Sean_Page
Collaborator
Collaborator

Do you have your External Event wrapped in a try / catch? I have found on many occasions that exceptions thrown in this scenario don't make thier way to the UI and I have only found it by catching the exception info with a Task Dialog box.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 4 of 7

luc.vallotP8MJ4
Contributor
Contributor

Hi spage,

 

sorry for the delay, I'm overbooked

 

my  event execute function contain a try catch, but the exception is never fired

the event creation and the event raise are enclosed in try catch too, but again no exception are fired

 

do you think that previous exceptions (during the dialog execution) can cause the problem ? and binding exception ?

 

Luc

 

0 Likes
Message 5 of 7

Sean_Page
Collaborator
Collaborator

Would you be able to share your code? Without that we are really throwing darts in the dark.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 6 of 7

luc.vallotP8MJ4
Contributor
Contributor

Hi,

 

it is difficult for us to share code since it should be necessary to extract it from the entire addin and peraps supress references to tools like caliburn

 

related question : I change ExternalEvent.Create by ExternalEvent.CreateJournable, but do you know how to analize the journal contains ?

0 Likes
Message 7 of 7

mhannonQ65N2
Collaborator
Collaborator

@luc.vallotP8MJ4 wrote:

 

do you think that previous exceptions (during the dialog execution) can cause the problem ? and binding exception ?

 


If the dialog hit an exception before where it would send the external event and caught it elsewhere, that would prevent the external event from being sent (this could also include any exception handling WPF or the button class may do).

That would look something like this:

try
{
    throw new ApplicationException();
    // <Code to send the external event>
}
catch()
{
    // Uh-Oh.
}

Assuming you are able to reproduce this on a development computer, I recommend running it in debug mode in Visual Studio and configuring it to break on all exceptions and possibly also setting some breakpoints at key points of your code--perhaps an exception is being thrown within the external event, preventing it from completing.

 

Also, are you using a modal dialog or a modeless dialog (I'm not sure if or how that affects your situation).

0 Likes