示例#1
0
    public static MyTask Run(IEnumerator e)
    {
        var t = new MyTask(e.ToString());

        t.Start(e);
        return(t);
    }
示例#2
0
        static async Task Main(string[] args)
        {
            DateTime dateTime    = DateTime.Now;
            var      dateTimeStr = dateTime.ToString();

            System.Console.WriteLine(dateTimeStr);

            var myTask    = MyTask.Run(() => DateTime.Now);
            var myStrTask = MyTask.Run(() => myTask.Result.ToString());
            var print     = MyTask.Run(() => Console.WriteLine(myStrTask.Result));


            // Console.WriteLine("Hello World!");

            bool run = true;

            Console.ForegroundColor = ConsoleColor.Green;
            Random r    = new Random();
            MyTask task = new MyTask(() =>
            {
                while (run)
                {
                    Console.Write(r.Next(0, 9));
                }
            });

            task.Start();

            task.Wait(500);
            run = false;

            Console.ReadLine();
        }
示例#3
0
    public static void Main()
    {
        MyTask <int> task = new MyTask <int>(Calculate, 10);

        Console.WriteLine("开始执行任务");
        task.Start();

        Console.WriteLine("调用 Start() 后返回,任务还没执行结束\n---------------------------------");

        task.Wait();
        Console.WriteLine("任务执行结束,结果为:{0}", task.result);
    }