public void StartAndWaitTasks()
        {
            List <Task> taskList = new List <Task>();

            taskList.Add(
                Task.Run(() =>
            {
                StmModified.Do <int>(new TransactionBlockModified <int>(
                                         (IStmTransaction <int> stmTransaction) =>
                {
                    variable1.Set(2, stmTransaction);
                    int temp = variable1.Get(stmTransaction);
                    temp    += 3;
                    variable2.Set(temp, stmTransaction);
                    List <Task> subTaskList = new List <Task>();
                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            int subTemp = variable1.Get(subStmTransaction);
                            variable2.Set(subTemp, subStmTransaction);
                        }
                                                 ));
                        //TODO subTask
                    })
                        );

                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            variable1.Set(3, subStmTransaction);
                        }
                                                 ));
                    })
                        );

                    Task.WaitAll(subTaskList.ToArray());
                    //TODO task
                }
                                         ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                StmModified.Do <int>(new TransactionBlockModified <int>(
                                         (IStmTransaction <int> stmTransaction) =>
                {
                    variable1.Set(2, stmTransaction);
                    int temp = variable1.Get(stmTransaction);
                    temp    += 3;
                    variable2.Set(temp, stmTransaction);
                    List <Task> subTaskList = new List <Task>();
                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            int subTemp = variable1.Get(subStmTransaction);
                            variable2.Set(subTemp, subStmTransaction);
                        }
                                                 ));
                        //TODO subTask
                    })
                        );

                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            variable1.Set(3, subStmTransaction);
                        }
                                                 ));
                    })
                        );

                    Task.WaitAll(subTaskList.ToArray());
                    //TODO task
                }
                                         ));
            })
                );

            Task.WaitAll(taskList.ToArray());
        }
示例#2
0
        private void RunAndWaitTasks()
        {
            List <Task> taskList = new List <Task>();

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    variable.Set(2, stmTransaction);
                    int temp = variable.Get(stmTransaction);
                    temp    += 3;
                    variable.Set(temp, stmTransaction);
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    variable.Set(3, stmTransaction);
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    variable.Set(4, stmTransaction);
                    Thread.Sleep(500);
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int temp = variable.Get(stmTransaction);
                    Thread.Sleep(1000);
                    temp += 9;
                    variable.Set(temp, stmTransaction);
                }
                                 ));
            })
                );

            Task.WaitAll(taskList.ToArray());
        }