Hi Grant,

TCP/IP sockets (in general) are designed to be owned by a single thread.
It is not permitted to block on the same socket by two different threads.  I don't know if this is your violation, but it is a problem.
If you want multi-threaded task handlers, the correct socket design is to have one thread handling the socket (8021) reads, and sending the event read to separate task handlers (in parallel).

The Receive() method is blocking for an event, and grabbing the first line of the event.
Does the error occur when Receive() get's it's first event, or when the second thread tries to block on a socket that is already owned by thread 1?
If you comment out "Task task2" does the error still occur?

Ian.


On Fri, May 16, 2014 at 7:24 AM, Grant Bagdasarian <GB@cm.nl> wrote:

Hello,

 

I’m trying to run the following code, but after a few seconds I get AccessViolationException:

 

class Program {

        static void Main(string[] args) {

 

            ESLconnection connection = new ESLconnection("192.168.1.1", 8021, "ClueCon");

            connection.SendRecv("event plain ALL");

            Task task1 = Task.Run(() => Receive(1, connection));

            Task task2 = Task.Run(() => Receive(2, connection));

            Console.ReadLine();

        }

 

        static void Receive(int id, ESLconnection connection) {

            while (connection.Connected() == 1) {

                ESLevent eslEvent = connection.RecvEvent();

                Console.WriteLine("{0} - {1}", id, eslEvent.Serialize("").Split(new char[] { '\r', '\n' })[0]);

            }

        }

    }

 

What the basic idea behind this is, is to have a Task continuously listening for a CHANNEL_HANGUP event, and have the other Task process the call in parallel.

Does the exception occur because multiple parallel tasks are trying to access the connection object?

 

Is the only solution to create a second ESLconnection (HANGUP Handler) and register it to receive only calls for a given UUID?

 

Regards,

 

Grant


_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org
http://www.freeswitchsolutions.com

FreeSWITCH-powered IP PBX: The CudaTel Communication Server
http://www.cudatel.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://wiki.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org