[Freeswitch-users] ESL C# Accessviolation

Grant Bagdasarian GB at cm.nl
Fri May 30 10:43:53 MSD 2014


Hello,

I posted about this issue a week ago, and Ian was kind enough to explain this to me. Search the maillist for “Managed ESL: AccessViolationException”.
In short, yes, accessing the same eslConnection from multiple threads causes this exception. I created a single object which listens for all the events and sends them to all other objects which subscribe to receive events.
This way you have only 1 thread listening for events on the socket, and can have multiple threads processing the events.

I believe you can send and receive on the same socket from 1 thread, since .net sockets are bi-directional.

From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Ferenc Sárközy
Sent: Thursday, May 29, 2014 4:40 PM
To: FreeSWITCH Users Help
Subject: [Freeswitch-users] ESL C# Accessviolation

Hi,
My C# app uses ESL to interact with FS. It plays wav files via bgapi and receives and processes the events of the playbacks.  The listening thread is started like  ManagedESLTest program:

ThreadPool.QueueUserWorkItem(new WaitCallback(getFsEventsInboundMode));

this thread ends up in a while loop where the events are received:

                while (eslConnection.Connected() == ESL_SUCCESS && !stopConnection)
                {
                    eslEvent = eslConnection.RecvEventTimed(50);
                    if (eslEvent != null)
                    {
                        onFreeswitcEvent(eslEvent );
                    }
                }
onFreeSwitchEvent calls ends up in an other thread.

bgapi commands is sent via the same eslConnection, I assume that the occasional Accessviolation at RecvEventTimed is caused by sending bgapi commands via the same eslConnection from an other thread. Could that be the cause?

Other related questions:
Is it safe to pass eslEvent to an other thread, or it should be serialized? If so is there a best practice to serialize?

Is there some kind of event buffer in eslConnection, or the RecvEvent misses all the events which "arrived" before the call?

Thank you in advance:
Ferenc




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20140530/0a0e9258/attachment-0001.html 


Join us at ClueCon 2013 Aug 6-8, 2013
More information about the FreeSWITCH-users mailing list