Exemple #1
0
        private void btT_Click(object sender, EventArgs e)
        {
            Trapeze trapeze  = new Trapeze();
            int     n        = Convert.ToInt32(tbN.Text);
            double  integral = trapeze.T(n);

            tbT.Text = Convert.ToString(integral);
        }
Exemple #2
0
        private async void GetResultT()
        {
            Trapeze trapeze = new Trapeze();
            int     n       = Convert.ToInt32(tbN.Text);
            int     a       = Convert.ToInt32(tbA.Text);
            int     b       = Convert.ToInt32(tbB.Text);

            pgb.Value = 0;
            bool answerReady = true;

            Progress <int> progress = new Progress <int>();

            progress.ProgressChanged += (sender, e) => { pgb.Value = e; };

            cts = new CancellationTokenSource();
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            double integral = 0;

            try
            {
                stopWatch.Start();
                integral = await trapeze.Calculate(n, a, b, cts.Token, progress, (x) =>
                {
                    return((10 * x) - Math.Log(14 * x));
                });

                stopWatch.Stop();
            }
            catch (OperationCanceledException)
            {
                tbT.Text    = "Отмена";
                answerReady = false;
            }
            catch
            {
                tbT.Text    = "Ошибка";
                answerReady = false;
            }

            if (answerReady)
            {
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
                if (integral == 0.0)
                {
                    tbT.Text = $"{trapeze.ErrorInformation}";
                }
                else
                {
                    tbT.Text    = Convert.ToString(integral);
                    tbTime.Text = Convert.ToString("Время выполнения " + elapsedTime);
                }
            }
            btT.Enabled      = true;
            btCancel.Enabled = false;
        }