Showing results for 
Search instead for 
Did you mean: 
This document was generated from CDN thread

Created by: Artem Repko on 05-06-2013 02:55:35 PM
I'm developing .NET application, that deals with CIL API and has more than one Session object.
I have a problem with handling events: the last session created receives events, all other - no.
Here the sample code:
1var Connector1 = new CtiosConnector();
5var Connector2 = new CtiosConnector();

Some extracts from realization:
 1class CtiosConnector : IGenericEvents, IDisposable
 3public bool ConnectSession() {
 5var session = new CtiOsSession();
 6session.AddEventListener(this, SubscriberList.eAllInOneList);
 8if (session.Connect(arguments) != CilError.CIL_OK) {
 9     return false;
12ConnectorSession = session;
15public bool LoginAgent() {
17var agent = new Agent();
19var waitObject = CreateWaitEventsObject(EventID.eSetAgentModeEvent);
20var setAgentResult = ConnectorSession.SetAgent(agent);
23After this command (i.e. for Connector2) all other instances (i.e. for Connector1) stop to receive any event!
28loginResult = agent.Login(loginArguments);
29ConnectorAgent = agent;
32public void OnEvent(object sender, EventPublisher.EventPublisherEventArgs eventArgs) {
33if (eventArgs == null) {return;}
34var receivedEvent = (EventID)eventArgs.iEventID;
35if (receivedEvent == EventID.eOnHeartbeat) {return;}
36switch (receivedEvent) {
37case EventID.eCallBeginEvent:
38   Console.WriteLine("Call begin. Login = {0}", login);
39// Only the second one session handles this event!
40   break;

In the API doc said:
Typically, an application has a single instance of the Session object, which is used by all other CIL objects to send and receive events. However, there are no restrictions on the number or types of Session objects one application can employ. It is possible, and sometimes desirable, to establish and manage multiple independent Sessions, for example to use multiple current event streams.If there is more than one Session object monitoring the same Agent or Call, each Session object will receive its own events.

The test project is attached.
Please help me with this problem. 

Added 06.06.2013: By the way, I've tried to use the same Agent for 2 sessions. Result is the same - only the 2nd Session receives events. It looks like some bug in CIL .NET.

Subject: RE: Multiple sessions: events handle only the last one
Replied by: David Lender on 06-06-2013 08:39:02 AM
In the CTIOS Web Service available from Custom Engineering ( we are using the .NET CIL  in C# and create a Session and Agent for every agent connecting in via a web page. It works great.
However, what we do is create an object that encapsulates the Session, Agent, and IGenericEvents in one object called the CTIObject. Then as new agents connect in, we instantiate a new instance of CTIObject for that agent. In the constructor for the CTIObject we create a new Session and Agent object, and set up the event listener using the reference to the newly created CTIObject as the event listener (i.e. CTIObject implements IGenericEvent interface). So all events are then handled by the CTIObject instance for that particular agent.
We think your problem is you are attempting to reuse the same object as your event listener for all sessions, which will not work. You will need a separate instance of the IGenericEvents object for each Session and Agent, so that the listener is unique to that particular Session and Agent object.
I’m attaching a sanitized version of the CTIObject that we use. Nothing propriety in it. We originally lifted it from the C# Combo Desktop Sample, and made just a few changes to get it to work in a multi-agent environment.  Feel free to use it. 

Subject: RE: Multiple sessions: events handle only the last one
Replied by: Artem Repko on 06-06-2013 12:37:06 PM
Thank you very much for your answer!
You can see in my simple test project (attached to the first message), that I'm using the same idea as you wrote: I have a class named CtiosConnector that encapsulated CtiosSession and Agent objects. This class implements IGenericEvents interface as well.
So I'm creating for every Agent connection new instance of CtiosConnector.
Difference is that this class is not inherited from CtiOsBase, but I have no idea why is it needed.
Could you tell the version of .NET CIL you are using?

Subject: RE: New Message from Artem Repko in Computer Telephony Integration Object S
Replied by: David Lender on 06-06-2013 01:59:15 PM
It’s not a Version issue. We’ve got CTIOS Web Services versions spanning from 7.0 to 9.1 that use the same code. So we know it’s not a version issue.

I see that you’re using a WaitObject inside of your class. I’m not sure that will work. I know there’s a big bold note in the Dev Guide (page 497) not to use a WaitObject inside of an Event Handler because it will cause event deadlocks. That may be it.  You need to rework the code to take that out, and just set a flag to indicate that Login is progress. Then in the handler for OnSetAgentModeEvent do the login.

Subject: RE: New Message from David Lender in Computer Telephony Integration Object
Replied by: David Lender on 06-06-2013 02:03:44 PM
If eliminating the WaitObjects doesn’t fix the issue, then you should engage the consulting services of our Custom Engineering Team.  Contact them at<>
There is a fee for this service.  I showed your code to a member of that team and he thinks the code will never work and needs  to be redesigned.   Sorry I can’t be of more help.

Subject: RE: New Message from David Lender in Computer Telephony Integration Object
Replied by: Artem Repko on 06-06-2013 02:48:05 PM
I've made changes and removed all waitObjects from the code. Unfortunately, it did not help.
Resulting test project - in attach (it's simpler than ever).
he thinks the code will never work and needs to be redesigned
I didn't catch that. The code is very simple. I don't know how to make it simpler. I'd glad to redisign it, but I don't know how.

Thank you for your trying to help, David.

Subject: RE: Multiple sessions: events handle only the last one
Replied by: Artem Repko on 18-06-2013 02:12:35 AM
Creating each session in it's own named thread solved the problem.
Detailed -
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers
Quick Links