Example #1
0
        private static object RunTask <T>(object arg, ParallelTask task)
        {
            Thread thread = Thread.CurrentThread;

            task.CancelToken.Token.Register(() =>
            {
                thread.Abort();
            });

            return(task.Func.Run(arg, task));
        }
Example #2
0
        public static ParallelTask StartNew <T>(object arg) where T : IParallelTaskFunc, new()
        {
            if (arg == null)
            {
                return(null);
            }

            RemoveTimeout();

            lock (_lck)
            {
                var pTask = new ParallelTask();
                pTask.Task = facotry.StartNew <object>(() => {
                    pTask.Func = new T();

                    return(RunTask <T>(arg, pTask));
                });

                tasks.Add(pTask.Task.Id, pTask);

                return(pTask);
            }
        }