Example #1
0
 private async Task _chat_UserTryingToSendMessage(byte[] arr)
 {
     try
     {
         var task = UserTryingToSendMessage?.Invoke(arr);
         if (task != null)
         {
             await task;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
Example #2
0
        private async void Work()
        {
            try
            {
                var messageText = _textBox.Text;

                if (string.IsNullOrWhiteSpace(messageText))
                {
                    return;
                }

                _sendMessageButton.IsEnabled = false;

                await Task.Run(() =>
                {
                }).ContinueWith(t =>
                {
                }, TaskScheduler.FromCurrentSynchronizationContext());


                byte[] arr = null;

                await await Dispatcher.InvokeAsync(async() =>
                {
                    await Task.Yield();
                    arr = Encoding.UTF8.GetBytes(_textBox.Text);
                });

                if (arr.Length > 100000000)
                {
                    MessageBox.Show("Сообщение имеет слишком большую длину");
                }
                else
                {
                    _textBox.Text = "";
                    UserTryingToSendMessage?.Invoke(arr);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                _sendMessageButton.IsEnabled = true;
            }
        }