Esempio n. 1
0
        private async void TryConnect()
        {
            try
            {
                var connectTask = Connect();

                var result = new ConnectingProgress(connectTask).ShowDialog(this);
                if (result == DialogResult.Cancel)
                    throw new OperationCanceledException();

                cancellationSource = new CancellationTokenSource();

                connection = await connectTask;
                try
                {
                    cancellationSource.Token.Register(() => { var ignored = connection.Disconnect(); });
                    await ReadMessages(connection, cancellationSource.Token);
                }
                finally
                {
                    var ignore = connection.Disconnect();
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    var errorDialog = new ErrorDialog() { ErrorMessage = ex.ToString() };
                    errorDialog.ShowDialog(this);
                }
                ShowConnectionDialog();
            }
            
        }
Esempio n. 2
0
        private async void TryConnect()
        {
            try
            {
                var connectTask = Connect();

                var result = new ConnectingProgress(connectTask).ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    throw new OperationCanceledException();
                }

                cancellationSource = new CancellationTokenSource();

                connection = await connectTask;
                try
                {
                    cancellationSource.Token.Register(() => { var ignored = connection.Disconnect(); });
                    await ReadMessages(connection, cancellationSource.Token);
                }
                finally
                {
                    var ignore = connection.Disconnect();
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    var errorDialog = new ErrorDialog()
                    {
                        ErrorMessage = ex.ToString()
                    };
                    errorDialog.ShowDialog(this);
                }
                ShowConnectionDialog();
            }
        }