Esempio n. 1
0
        public async Task <int> testMethod1()
        {
            System.Random r = new System.Random();

            int resultCount = 0;
            var tasks       = new List <Task <int> >();

            for (int i = 0; 10 > i; i++)
            {
                //Thread.Sleep(r.Next(10,30));
                SC.WriteLine("OK 1:{0}", i);
                testTask task = new testTask(i);
                task.wait = r.Next(100, 300);
                tasks.Add(Task.Run <int>(() => { return(task.inc()); }));
            }
            var result = await Task.WhenAll(tasks);

            foreach (Task <int> task in tasks)
            {
                SC.WriteLine("OK 2:{0}", task.Result);
                resultCount += task.Result;
            }

            return(resultCount);
        }
Esempio n. 2
0
 public int inc()
 {
     Thread.Sleep(wait);
     SC.WriteLine("OK 3:{0} wait={1}", val_, wait);
     return(val_ + 1);
 }
Esempio n. 3
0
 private int inc(int val, int wait)
 {
     Thread.Sleep(wait);
     SC.WriteLine("NG 3:{0} wait={1}", val, wait);
     return(val + 1);
 }