Esempio n. 1
0
 void Setup_Thread()
 {
     ThreadStarter Ts = new ThreadStarter();
     Ds_Generic D = new Ds_Generic(this.Process);
     Ts.Setup(D, null, this);
     this.mThread_Process = Ts.pThread;
 }
Esempio n. 2
0
 private void StartGamesExecutionThreads()
 {
     Logger.LoadBalancerLog("Starting Games Executors according to Threadcount of CPU");
     for (int id = 0; id < LogicalCoreCount; id++)
     {
         GamesExecutors.Add(new GamesExecutor(id, FrameWaitConditions[id % (int)CPULoadBalanceFactor]));
         ThreadStarter.ThreadpoolDebug("Games Executor Thread " + id.ToString(), GamesExecutors[id].Run);
     }
 }
        public void StartApplicationWithCmdArgs(string[] args)
        {
            int[] results = new int[2];

            Validator validator = new Validator();

            if (validator.ValidateInputCommandArgs(args, ref results))
            {
                ThreadStarter threadStarter = new ThreadStarter();
                threadStarter.ProccessThreadPoolMethod(results[0], results[1]);
            }
        }
Esempio n. 4
0
        private void Run()
        {
            CommandList cl = new CommandList(commandBox.Text);

            ThreadStarter.StartBackround(new RunWorkerDelegate(RunWorker), cl);
        }
Esempio n. 5
0
        /// <summary>
        /// Выполнить действие в отдельном потоке и транзакции
        /// ---
        ///  объекты должны быть независимы в действии, можно передавать Id сущности и после выполнения в исходном потоке вызвать Refresh
        /// </summary>
        /// <param name="action"> действие </param>
        /// <param name="name">название операции</param>
        /// <param name="errorCallback">обработка ошибки</param>
        /// <param name="successCallback">действие после успеха</param>
        /// <param name="minutes">количество минут выделенное на операцию (максимум 9)</param>
        public static void InNewThread(
            this Action action,
            string name,
            Action <Exception> errorCallback,
            Action successCallback,
            int minutes = 2)
        {
            Exception exception = null;
            Thread    thread    = null;

            try
            {
                thread = ThreadStarter.StartNewThread((ThreadStart) delegate
                {
                    var backgroundTask = new BackgroundTask(() =>
                    {
                        var securityService = Locator.GetService <ISecurityService>();
                        securityService.RunByUser(UserManager.Instance.Load(SecurityConstants.AdminUserUid),
                                                  () =>
                        {
                            var unitOfWorkManager = Locator.GetServiceNotNull <IUnitOfWorkManager>();
                            using (var unitOfWork = unitOfWorkManager.Create(string.Empty, true, System.Data.IsolationLevel.ReadCommitted))
                            {
                                try
                                {
                                    action.Invoke();
                                    unitOfWork.Commit();
                                }
                                catch (Exception ex)
                                {
                                    unitOfWork.Rollback();
                                    exception = ex;
                                }
                            }
                        });
                    }, typeof(Action), action.Method.Name, name);
                    backgroundTask.Execute();
                });
                thread.IsBackground = true;
                if (!thread.Join(TimeSpan.FromMinutes(minutes)))
                {
                    thread.Abort();
                    var message = $"Действие \"{name}\" выполнялось более {minutes} минут и было прервано";
                    exception = exception != null ? new Exception(message, exception) : new Exception(message);
                }
                if (exception != null)
                {
                    if (errorCallback != null)
                    {
                        errorCallback.Invoke(exception);
                    }
                    else
                    {
                        throw exception;
                    }
                }
                else
                {
                    successCallback?.Invoke();
                }
            }
            catch (ThreadAbortException)
            {
                thread?.Abort();
                throw;
            }
        }
 public void StartApplicationWithConsoleInput()
 {
     UserHelper userHelper = new UserHelper();
     ThreadStarter threadStarter = new ThreadStarter();
     threadStarter.ProccessThreadPoolMethod(userHelper.GetThreadCount(), userHelper.GetArrayOfThreadIncrement());
 }
 void PreparedQuerySessionChecker_Start()
 {
     ThreadStarter Ts = new ThreadStarter();
     Ds_Generic D = new Ds_Generic(this.PreparedQuerySessionChecker);
     Ts.Setup(D, null, this);
     this.mThread_PreparedQuerySessionChecker = Ts.pThread;
     Ts.Start();
 }