예제 #1
0
        private async void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            btnUpload.IsEnabled = false;
            btnCancel.IsEnabled = true;

            isUploading = true;

            Model.MessageLog = "";

            if (Model.SelectedComPort == null)
            {
                System.Windows.MessageBox.Show("Please select a serial port");
                return;
            }
            else if (Model.SelectedFile == null && Model.PickedFile == null)
            {
                System.Windows.MessageBox.Show("Please select a template");
                return;
            }

            var t = new Thread(() =>
            {
                var uploader             = new Uploader();
                this.Cancel              = () => uploader.Cancel();
                uploader.Message        += Uploader_Message;
                uploader.UploadProgress += Uploader_UploadProgress;
                uploader.Upload(Model.SelectedComPort, File.ReadAllBytes(Model.PickedFile ?? Model.SelectedFile), Model.UploadBaudRate, Model.ResetNextionAtUpload);

                Dispatcher.Invoke(() =>
                {
                    Cancel = null;
                    btnUpload.IsEnabled = true;
                    btnCancel.IsEnabled = false;
                    isUploading         = false;
                });
            });

            t.Start();
        }
예제 #2
0
 private void ButtonCancel_Click(object sender, RoutedEventArgs e)
 {
     uploader.Cancel();
 }