Пример #1
0
        private void heuristicRectangleButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (board.Blocks == null)
            {
                return;
            }
            var watch = new System.Diagnostics.Stopwatch();
            Tuple <int[, ], int> result = new Tuple <int[, ], int>(new int[0, 0], 0);
            Task task = Task.Factory.StartNew(() =>
            {
                watch.Start();
                result = board.FastRectangle(token);
                watch.Stop();
            }, token).ContinueWith(_ => {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                var bitmap = BitmapGenerator.DrawSolution(result.Item1);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
                labelInfo1.Text       = $"Time: {watch.ElapsedMilliseconds} ms";
                labelInfo2.Text       = $"Cuts: {result.Item2}";
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Пример #2
0
        private void optimalSquareButton_Click(object sender, System.EventArgs e)
        {
            CancelRunningTask();
            var token = _tokenSource.Token;

            if (board.Blocks == null)
            {
                return;
            }
            var watch = new System.Diagnostics.Stopwatch();

            int[,] result = new int[0, 0];
            Task task = Task.Factory.StartNew(() =>
            {
                watch.Start();
                result = board.Square(token);
                watch.Stop();
            }, token).ContinueWith(_ => {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                var bitmap = BitmapGenerator.DrawSolution(result);

                pictureBox.ClientSize = new Size(bitmap.Width, bitmap.Height);
                pictureBox.Image      = bitmap;
                labelInfo1.Text       = $"Time: {watch.ElapsedMilliseconds} ms";
                labelInfo2.Text       = $"Square size: {result.GetLength(0)}x{result.GetLength(0)}";
            }, _tokenSource.Token, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }