private async Task Connect(string hostname, int port, uint timeout = 5000) { long endTime = DateTime.Now.Ticks + timeout * 10000; while (DateTime.Now.Ticks < endTime) { try { Inferior = new Inferior(); Inferior.Attached += duktape_Attached; Inferior.Detached += duktape_Detached; Inferior.Throw += duktape_ErrorThrown; Inferior.Print += duktape_Print; Inferior.Status += duktape_Status; await Inferior.Connect(hostname, port); return; } catch (SocketException) { // a SocketException in this situation just means we failed to connect, // likely due to nobody listening. we can safely ignore it; just keep trying // until the timeout expires. } } throw new TimeoutException(); }