# Unity editor stalling on second attempt to play

I am attempting to use a Tobii TX300 eye-tracker as an input device for Unity. This device is connected via LAN (TCP connection managed by Tobii SDK). The Tobii SDK has appropriate methods (I am writing in C#/mono) for opening and closing connections with the device.

I can 'play' my application once within the Unity editor and everything works as expected, but on the second attempt to 'play' the game, the editor stalls. The problem also occurs if I am currently playing the game in the editor, and then synchronize any code changes. I notice that this thread remains open:

mono.dll!mono_unity_socket_security_enabled_set+0x1e04 (there are usually at least 3-4 threads with the same name, but one always consumes a higher amount of cpu).

If I kill it manually using ProcessHacker then the Unity editor resumes normal operation.

The problem also occurs if I build the application into an executable. The game will play fine, but as soon as I attempt to exit then the application freezes, and I have to manually kill the process.

void Start ()
{
Library.Init();
eyeTracker.StartTracking();
}

void OnApplicationQuit()
{
eyeTracker.StopTracking();
eyeTracker.Dispose();
}


Does anyone have any suggestions on why this thread is remaining open, or how to release resources within Unity scripts?