Пример #1
0
        /// <summary>
        /// Click handler for the shutdownDevice button.
        /// </summary>
        /// <param name="sender">The caller of this method.</param>
        /// <param name="e">The arguments associated with this event.</param>
        private void ShutdownDevice_Click(object sender, RoutedEventArgs e)
        {
            bool reenableDeviceControls = false;

            this.ClearOutput();
            this.EnableConnectionControls(false);
            this.EnableDeviceControls(false);

            StringBuilder sb           = new StringBuilder();
            Task          shutdownTask = new Task(
                async() =>
            {
                sb.Append(this.MarshalGetCommandOutput());
                sb.AppendLine("Shutting down the device");
                this.MarshalUpdateCommandOutput(sb.ToString());

                try
                {
                    await portal.Shutdown();
                }
                catch (Exception ex)
                {
                    sb.AppendLine("Failed to shut down the device.");
                    sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
                    reenableDeviceControls = true;
                }
            });

            Task continuationTask = shutdownTask.ContinueWith(
                (t) =>
            {
                this.MarshalUpdateCommandOutput(sb.ToString());
                this.MarshalEnableDeviceControls(reenableDeviceControls);
                this.MarshalEnableConnectionControls(true);
            });

            shutdownTask.Start();
        }