Example #1
0
        private async void DrawSizeGraph_Click(object sender, EventArgs e)
        {
            if (TryValidateInput())
            {
                sizeGrpahCTS = new CancellationTokenSource();
                var cancellationToken = sizeGrpahCTS.Token;
                this.DrawSizeGraph.Enabled       = false;
                this.DrawSizeGraphCancel.Enabled = true;

                this.LoadingBox.Show();
                //var generateTask = Task<GenerateDataPoint>.Run(() => GenerateGraph());
                //var task = await Task.Factory.StartNew<GenerateDataPoint>(() => GenerateGraph());
                GenerateDataPoint dataPoint = null;

                dataPoint = await Task.Factory.StartNew <GenerateDataPoint>(() => GenerateGraph(cancellationToken, PointXYGenerate), cancellationToken);

                if (dataPoint != null)
                {
                    AfterGenerateWorkComplete(dataPoint, this.SizeGraph);
                }

                //task.ContinueWith(async(dataPoint) => AfterGenerateWorkComplete(dataPoint.Result));
                LoadingBox.Hide();
                this.DrawSizeGraphCancel.Enabled = false;
                this.DrawSizeGraph.Enabled       = true;
            }
            else
            {
                ShowErrorMessage();
            }
        }
Example #2
0
        private async void button4_Click(object sender, EventArgs e)
        {// 下一个配方按钮
            if (checkRecipeSelected())
            {
                loadingBox.Show();
                loadingBox.Update();

                var selectedItem = getSelectedRecipes() as ListBoxItemInfo;

                bool isWithinErrorThreshold = await Task.Run(() =>
                {
                    for (int i = 0; i < 10; i++) // 多次采样验证
                    {
                        Thread.Sleep(200);
                        double cha = selectedItem.CurrentQuality
                                     - selectedItem.StandardQuality;
                        if (Math.Abs(cha) > Settings.ErrorThreshold)
                        {
                            return(false);
                        }
                    }
                    return(true);
                });

                loadingBox.Hide();

                if (isWithinErrorThreshold)
                {
                    if (!checkLastRecipeSelected())
                    {
                        listBox1.SelectedIndex += 1;
                    }
                }
                else
                {
                    MessageBox.Show("当前值不够稳定,未满足误差要求");
                }
            }
        }