Esempio n. 1
0
        async void TcpWorker(IPEndPoint addr)
        {
            var client = new TcpClient();

            try
            {
                var token = WorkerAbort.Token;
                token.ThrowIfCancellationRequested();
                await client.ConnectAsync(addr.Address, addr.Port).ConfigureAwait(false);

                Dispatcher.Post(ReflectConnection);
                var stream = client.GetStream();
                WorkerAbort.Token.Register(() => { stream.Close(); });

                ProcessWriteQueue(stream).IgnoreExceptions();
                while (!token.IsCancellationRequested)
                {
                    await ProcessServerMessage(stream);
                }
            }
            catch (ObjectDisposedException) { }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                client.Close();
                Dispatcher.Post(ReflectDisconnection);
            }
        }
Esempio n. 2
0
 void Log(string text)
 {
     UIDispatcher.Post(() => TbLog.AppendText(text));
 }