cancel
Showing results for 
Search instead for 
Did you mean: 

Problem: Item-Events are sent from different threads (C#)

Former Member
0 Kudos

Hi,

we are using C# and our AddOn uses the Event-system (MainClass.SAPApplication.ItemEvent) exceedingly. For this we use ONE delegate (because otherwise toggling the bubbleEvent does not stop the execution) and from there we push the events to the different objects.

We noticed that some Events reached our AddOn later then expected and sometimes even in between and after a while we saw (using System.AppDomain.GetCurrentThreadId()), that the Events are indeed coming from different threads.

There seems to be a thread-pool and the single Events will be sent along on different threads.

In short: This is disastrous. We rely on a certain order of events coming in and this does obviously not work well together with threading. We can't lock the Event-pushing because sometimes we generate Events on our own during the Event-consumption and locking will then lead to deadlocks.

Is this threading-behaviour intended? Is it a problem of C#? Can it be solved somehow?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks, cleared up all

former_member185703
Active Contributor
0 Kudos

Hi,

What you observe is first of all a COM behavior (regardless which dev. language you use):

When you handle an event and in this handler call the COM interface in the other direction, the COM interface is unblocked and you will receive further events; you might even find your event handler getting called a second time(!) before you passed back control in your code when handling the first event!

I.e. you need to reflect this behavior in the design of your application by using kernel objects etc., but it will always be difficult.

Sorry for the bad news...

Regards,

Frank