Exemplo n.º 1
0
        private void taskAndAction_Click(object sender, EventArgs e)
        {
            MyCompute mc = new MyCompute();

            mc.Data1 = 24.22f;
            mc.Data2 = 11;
            Action fCompute = () => { MessageBox.Show("taskAndAction"); };

            Task.Run(fCompute);
        }
Exemplo n.º 2
0
        private void btnThreadLikeTask_Click(object sender, EventArgs e)
        {
            MyCompute mc = new MyCompute();

            mc.Data1 = 24.22f;
            mc.Data2 = 11;
            Action fCompute  = new Action(mc.Compute3);
            Thread thCompute = new Thread(new ThreadStart(fCompute));

            thCompute.Start();
            thCompute.Join();
            MessageBox.Show("Result = " + mc.Res.ToString());
        }
Exemplo n.º 3
0
        private void computeTask_Click(object sender, EventArgs e)
        {
            MyCompute mc = new MyCompute();

            mc.Data1 = 24.22f;
            mc.Data2 = 11;
            Func <float, float, double> fptr = new Func <float, float, double>(mc.Compute2);
            var task = new Task <double>(() => mc.Compute2(23.67f, 12.66f));

            task.Start();
            var result = task.Result;

            MessageBox.Show(result.ToString());
        }