cancel
Showing results for 
Search instead for 
Did you mean: 

How to identify when B1 disconnects the addon

leandro_daminelli2
Participant
0 Kudos
127

Hello everyone.

When I throw an exception inside an event, B1 disconnects the add-on. Is there any way to find out that this happened?

I did some tests and even when the addon got disconnected I still can send messages via MessageBox for example. The only difference that I saw is that B1 does not send events anymore.

I need to know when this happens because the application will still run after being disconnected, so I need to kill the task to avoid many executables running for nothing.

Thank you in advice.

View Entire Topic
former_member185682
Active Contributor
0 Kudos

Hi Leandro,

Who gets your exception? When an exception is raised you need make the appropriate treatment.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

leandro_daminelli2
Participant
0 Kudos

Diego, this is not my point.

When I throw the exception, B1 catches it and disconnects the addon. I don't have any problem with it, I just want to know how to identify when B1 disconnects the addon.

pedro_magueija
Active Contributor
0 Kudos

Hi Leandro,

Your addon gets disconnected because it threw an unhandled exception. It's good practice to run event handlers inside a try/catch block and process any exceptions coming from the event handler.

Note that by preventing unhandled exception to propagate, you don't need to know "when" the addon gets disconnected to kill the task, since you won't get disconnected.

Of course it also good practice to log the exception somehow.

Good luck.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leandro_daminelli2
Participant
0 Kudos

Please lets focus on my question.

I know that and all my event handlers are under try/catch block.

The point is that sometimes a developer can forget the try/catch statement in a task or separeted thread and we have some costumers which use cloud servers complaining about more than one instance of our addon running for the same user.

All I need is to develop some method to prevent this from happen when we have some bug in our code.

pedro_magueija
Active Contributor
0 Kudos

Hi Leandro,

Have a look at: AppDomain.UnhandledException Event (System)


AppDomain currentDomain = AppDomain.CurrentDomain;

  currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

That will make sure that any Unhandled exception thrown in your application will get caught by this handler.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leandro_daminelli2
Participant
0 Kudos

Hi Pedro.

I did some tests and the event is unfortunately not triggered.

Seems like B1 catches the exception so it's not an unhandled exception.