public Task ConnectAsync() { _tokenSource = new CancellationTokenSource(); if (!Parameters.ContainsKey("type")) { Parameters.Add("type", "client"); } Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); bool executed = _socket.ConnectAsync(wsUri, CancellationToken.None).Wait(ConnectTimeout); if (!executed) { throw new TimeoutException(); } _receiverLoop = new Thread(ReceiverLoop); _receiverLoop.Start(_tokenSource.Token); _senderLoop = new Thread(SenderLoop); _senderLoop.Start(_tokenSource.Token); return(Task.CompletedTask); }
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { var res = MessageBox.Show(this, "You are closing the application. All unsaved changes will be lost." + "Would you like to save the invoices database now?", "Save changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Cancel) { e.Cancel = true; return; } else if (res == DialogResult.Yes) { bool success; SaveDatabase(out success); if (!success) { e.Cancel = true; return; } } EIO.DoDeleteOnExit(); }
public Task ConnectAsync() { Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters); _client = new WebsocketClient(wsUri); _client.MessageReceived.Subscribe(Listen); _client.DisconnectionHappened.Subscribe(info => { if (info.Type != DisconnectionType.ByUser) { CloseHandler(); } }); var token = new CancellationTokenSource(ConnectTimeout).Token; token.ThrowIfCancellationRequested(); try { _client.Start().Wait(token); } catch (Exception e) { if (e is OperationCanceledException) { throw new TimeoutException(); } throw e; } return(Task.CompletedTask); }
public Task ConnectAsync() { var token = new CancellationTokenSource(ConnectTimeout).Token; _tokenSource = new CancellationTokenSource(); Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); Task connectionTask; bool executed = false; try { connectionTask = _socket.ConnectAsync(wsUri, _tokenSource.Token); executed = connectionTask.Wait(TimeSpan.FromSeconds(1)); } catch (System.Exception) { InvokeConnectError(); return(Task.CompletedTask); } if (!executed) { throw new TimeoutException(); } Listen(); return(Task.CompletedTask); }
public async Task ConnectAsync() { _tokenSource = new CancellationTokenSource(); Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Path, Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); await _socket.ConnectAsync(wsUri, CancellationToken.None); Listen(); }
public Task ConnectAsync() { _tokenSource = new CancellationTokenSource(); Uri wsUri = _urlConverter.HttpToWs(_uri, EIO.ToString(), Parameters); if (_socket != null) { _socket.Dispose(); } _socket = new ClientWebSocket(); bool executed = _socket.ConnectAsync(wsUri, CancellationToken.None).Wait(ConnectTimeout); if (!executed) { throw new TimeoutException(); } Listen(); return(Task.CompletedTask); }
public string ReadText(Image img) { string tempImageFileName = EIO.GetTempFileName("jpg"); string tempTextFileName = tempImageFileName; img.Save(tempImageFileName); try { RunProcess(tempImageFileName, tempTextFileName); } catch (Exception ex) { throw new Exception("Failed to read text.", ex); } string ret = System.IO.File.ReadAllText(tempTextFileName + ".txt"); TryDeleteFile(tempImageFileName); TryDeleteFile(tempTextFileName + ".txt"); return(ret); }