Skip to Content
0

Running multiple Application inside one Addon

Nov 23, 2016 at 09:24 AM

90

avatar image

I am using SAP Business One 9.2 SDK UI and DI API in C# to write an addon which executes business logic and creates numerous forms on many parts of B1. I am thinking about making it modular, so every module has its own event handlers, menu registers and event filters. Is it a good idea to create multiple SAPbouiCOM.Application instances and pass them to the modules? Let's say I have 10-20 different modules and they subscribe to different Application.*events* and set different Application.SetFilters(). Will It slow down B1 like If I am running too many addons?

Edit.: All the modules register their events on the same thread and created on the same thread, becouse the SDK is single threaded/ not thread safe.

sap b1 | c# | ui | uiapi | b1 | di | diap
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Pedro Magueija Nov 23, 2016 at 10:22 AM
0

Hi Szabolcs,

The SAPbouiCOM.Application object is created when you connect with B1. You shouldn't create many connections (issues with memory and speed will rise).

You can create a connection and pass the created application object to your modules, they can then register their events with that application object. On a side note, you should probably pass also the SAPbobsCOM.Company to your modules.

When registering directly with the application object you'll have to manage the bubbleEvent flag carefully.

Pedro Magueija

LinkedIn | Twitter | Blog

Show 6 Share
10 |10000 characters needed characters left characters exceeded

It I use one Application, I will slowly defeat the purpose of event filters, because as I add my modules to the addon, I will add more and more filters and every module will get notified by the application. If there are multiple applications, each has its own filters and will only notify the modules it supports. The question is the balance, does it worth it?

0

Hi Szabolcs,

Not quite, if you add more and more filters it will still be for specific forms (and in 9.2 even specific items), thus you'll only receive the events on those forms (which is what you want).

Also, note that the filters are valuable in the sense that in the same form you only get the events that you are interested in. If you have many filters registered but you never get to the point where they are triggered that is fine. But being in a form where 100 events are triggered but you are only interested in one, that is where filters show their worth.

Having multiple application (connections) will be very heavy in terms of memory consumption and speed once you start having many modules.

My recommendation is that you use only one connection, but ultimately it's your decision.

Pedro Magueija

LinkedIn | Twitter | Blog

1

I just realized something. Correct me if I am wrong please.

If I register two different methods for the same event and one would like to set the BubbleEvent to false, then the one that would like to set the BubbleEvent to false needs to be registered last, otherwise the ones that would leave it as true would set the flag to true in the sdk and even if the last one sets it to false, it wouldn't work., because its get overwritten by a true value later.

This creates some pretty nasty dependency between my modules. That is why I first thought about creating multiple Application objects.

I think I should just introduce a rule for my modules which wouldn't allow the handling of the same event for different modules.

0

Hi Szabolcs,

Yep, that is what I meant with my above post:

- When registering directly with the application object you'll have to manage the bubbleEvent flag carefully.

One common approach is to check the current value of BubbleEvent before handling the event.

If the value is false, don't call your handler.

Pedro Magueija

LinkedIn | Twitter | Blog

1

Thanks, that was a really useful tip.

0

Hmm. But I cannot check the BubbleEvent's value, because it is defined as an 'out' paramter, meaning I first need to assign a value to it. :(

0
Pedro Magueija Nov 25, 2016 at 11:50 AM
1

You're right because you are registering with the application object event.

You can raise your own event (same arguments, except for the out bubbleEvent, make it a simple argument).

You can then use stopEvent &= true or false; in your handlers.

Finally, assign your bubbleEvent to B1's BubbleEvent.

pseudo code:

... OnItemEvent(ItemEvent pVal, out bool BubbleEvent)
{  
bool stopEvent; 
RaiseMyItemEvent(pVal, ref stopEvent); 
BubbleEvent = stopEvent;
}

Does it make sense?

ps: sorry about the poor indenting but this new editor is getting on my nerves (I wrote this reply twice now).

Pedro Magueija

LinkedIn | Twitter | Blog

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Yes, thank you. I will do it the way you suggested. :)

0