Beispiel #1
0
        private void SyncProcess_Click(object sender, EventArgs e)
        {
            Stopwatch         myWatch = new Stopwatch();
            OperationWithTask obj     = new OperationWithTask();

            myWatch.Start();
            textBox1.Text = obj.GetPrintContent("");
            myWatch.Stop();
            textBox1.Text = textBox1.Text + $"Total Time elapsed is {myWatch.ElapsedMilliseconds.ToString()}";
        }
Beispiel #2
0
        private async void AsyncWithTaskRun_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;

            /*
             * We have seen what async/await does inside AsyncWithNewTask_Click method.
             * The same could be achieved using Task.Run, what we do here as Step 1
             */
            Stopwatch         myWatch = new Stopwatch();
            OperationWithTask obj     = new OperationWithTask();

            myWatch.Start();
            textBox1.Text = await Task.Run <string>(() => obj.GetPrintContent(""));

            myWatch.Stop();
            textBox1.Text = textBox1.Text + $"Total Time elapsed is {myWatch.ElapsedMilliseconds.ToString()}" + Environment.NewLine;

            /*
             * Step 2 ... Now we are going to change the code for
             * parallel execution
             */
            textBox1.Text = textBox1.Text + "------------------" + Environment.NewLine + Environment.NewLine;
            await PrintWebSiteContentParallely();
        }