Esempio n. 1
0
        // Try sending the message to the Server.
        private async void SendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (commModule == null)
                {
                    SendButton.Content = "Connect again then click here to send the request.";
                    return;
                }
                if (sendingRequest)
                {
                    SendButton.Content = "Still sending previous request, please wait.";
                    return;
                }

                SendButton.Content = "Sending...";
                sendingRequest     = true;

                // Send http request. But do this heavy lifting outside of the UI thread.
                bool result = await Task <bool> .Factory.StartNew(() =>
                {
                    return(commModule.SendHttpQuery());
                });

                if (!result)
                {
                    Diag.DebugPrint("Failed to send HttpRequest. Please try again.");
                    SendButton.Content = "Failed to send. Please try again";
                }
                else
                {
                    SendButton.Content = "SendRequest";
                }
                sendingRequest = false;
            }
            catch (Exception ex)
            {
                SendButton.Content = "Failed to send. Please try again";
                sendingRequest     = false;
                Diag.DebugPrint("Exception occured while sending HttpRequest. Exception: " + ex.ToString());
            }
        }