/// <summary>
        /// Выполняет операцию в фоновом потоке, не блокируя UI элементы формы. Может быть вызван сколько угодно раз подряд
        /// </summary>
        /// <param name="args">Начальные аргументы для потока</param>
        /// <param name="action">Метод, выполняемый в фоновом потоке</param>
        /// <param name="completed">Метод, выполняемый после окончания фонового потока</param>
        /// <param name="cancellationToken">Токен для воркеров с возможностью остановки</param>
        public static void RunAsync(object args, DoWorkDelegate action, CompletedDelegate completed, CancellationTokenSource cancellationToken = null)
        {
            Worker w = new Worker(args, action, completed, null, false, cancellationToken);

            w.Complited += new EventHandler(w_Complited);
            Count++;
        }
Exemple #2
0
 public ThreadGun(Func <T, Task> func, IEnumerable <T> inputs, int threadCount,
                  CompletedDelegate completedEvent, ExceptionOccurredDelegate exceptionOccurredEvent)
 {
     Completed         += completedEvent;
     ExceptionOccurred += exceptionOccurredEvent;
     _threadCount       = threadCount;
     _func              = func;
     _inputs            = inputs;
 }
Exemple #3
0
 public ThreadGun(Action action, int magazineCount, int threadCount,
                  CompletedDelegate completedEvent, ExceptionOccurredDelegate exceptionOccurredEvent)
 {
     Completed         += completedEvent;
     ExceptionOccurred += exceptionOccurredEvent;
     _threadCount       = threadCount;
     _action            = action;
     _magazineCount     = magazineCount;
 }
Exemple #4
0
 public ThreadGun(Action <T> actionT, IEnumerable <T> inputs, int threadCount,
                  CompletedDelegate completedEvent, ExceptionOccurredDelegate exceptionOccurredEvent)
 {
     Completed         += completedEvent;
     ExceptionOccurred += exceptionOccurredEvent;
     _threadCount       = threadCount;
     _actionT           = actionT;
     _inputs            = inputs;
 }
        public Worker(object args, DoWorkDelegate action, CompletedDelegate completedAction, ProgressDelegate progressAction, bool canReport, CancellationTokenSource cancellationToken)
        {
            this.bWork = new BackgroundWorker();
            this.bWork.WorkerReportsProgress = canReport;
            this.Action               = action;
            this.CompletedAction      = completedAction;
            this.ProgressAction       = progressAction;
            bWork.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bWork_RunWorkerCompleted);
            bWork.DoWork             += new DoWorkEventHandler(bWork_DoWork);
            bWork.ProgressChanged    += new ProgressChangedEventHandler(bWork_ProgressChanged);

            if (cancellationToken != null)
            {
                bWork.WorkerSupportsCancellation = true;
            }
            bWork.RunWorkerAsync(args);
        }
Exemple #6
0
        /* code appelé à partir de la thread de travail pour indiquer l'achèvement
         * nous passons aussi un paramètre pour indiquer si nous
         * avons réellement terminé ou si nous avons annulé l'opération
         * l'appel à l'UI est fait sur la thread UI */
        public void Completed(bool cancelled)
        {
            try
            {
                BoolRunning  = false;
                BoolCanceled = cancelled;
                CompletedDelegate comp = new CompletedDelegate(((IClient)frmClient).Completed);
                object[]          ar   = { cancelled };

                /* appelle le formulaire client sur la thread UI
                 * pour indiquer l'achèvement */
                frmClient.Invoke(comp, ar);
            }
            catch (Exception)
            {
            }
        }
Exemple #7
0
            public static T Retry <T>(RetryDelegate <T> Action, CompletedDelegate <T, Object> Completed,
                                      Object completed_delegate_object, int wait_secs, int max_tries, TimeSpan timeout_secs)
            {
                T        result      = default(T);
                DateTime start       = DateTime.UtcNow;
                int      tries       = 0;
                var      method_name = Action.Method.Name;

                while (TimeToGiveUp(start, timeout_secs, tries, max_tries) == false)
                {
                    try
                    {
                        tries++;
                        result = Action.Invoke();
                        if (Completed(result, completed_delegate_object) == true)
                        {
                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        GenUtils.PriorityLogMsg("exception", "RetryDelegate: " + method_name,
                                                e.Message + e.StackTrace);
                        throw (e);
                    }
                    HttpUtils.Wait(wait_secs);
                }

                if (TimedOut(start, timeout_secs))
                {
                    throw RetryTimedOut;
                }

                if (ExceededTries(tries, max_tries))
                {
                    throw RetryExceededMaxTries;
                }

                return(result);                 // default(T)
            }
 public static void Join(ulong lobbyId, CompletedDelegate<LobbyEnterInfo> callback)
 {
     Lobby lobbyId2 = new Lobby( lobbyId );
     lobbyId2.Join(callback);
 }
 public unsafe void Join(CompletedDelegate<LobbyEnterInfo> callback)
 {
 }
        // public unsafe static Result ConvertLobby(LobbyCreated_t* lobby, ref Lobby result)
        // {
        //     return false;
        // }

        // public unsafe static void ConvertJoin(LobbyEnter_t* info, ref LobbyEnterInfo result)
        // {
        // }

        public unsafe static void Create(LobbyTypeEnum lobbyType, int maxMembers, CompletedDelegate<Lobby> callback)
        {
        }
Exemple #11
0
 public unsafe void Join(CompletedDelegate <LobbyEnterInfo> callback)
 {
 }
Exemple #12
0
 public ThreadGun(Action action, int magazineCount, int threadCount,
                  CompletedDelegate completedEvent) : this(action, magazineCount, threadCount, completedEvent, null)
 {
 }
Exemple #13
0
 public ThreadGun(Func <T, Task> func, IEnumerable <T> inputs, int threadCount,
                  CompletedDelegate completedEvent) : this(func, inputs, threadCount, completedEvent, null)
 {
 }
Exemple #14
0
 public ThreadGun(Action <T> actionT, IEnumerable <T> inputs, int threadCount,
                  CompletedDelegate completedEvent) : this(actionT, inputs, threadCount, completedEvent, null)
 {
 }
Exemple #15
0
        public static void Join(ulong lobbyId, CompletedDelegate <LobbyEnterInfo> callback)
        {
            Lobby lobbyId2 = new Lobby(lobbyId);

            lobbyId2.Join(callback);
        }
Exemple #16
0
 public CalTask(CompletedDelegate delegatemothod)
 {
     completed = delegatemothod;
     status    = CalStatus.EStatus.无计算;
 }
Exemple #17
0
        // public unsafe static Result ConvertLobby(LobbyCreated_t* lobby, ref Lobby result)
        // {
        //     return false;
        // }

        // public unsafe static void ConvertJoin(LobbyEnter_t* info, ref LobbyEnterInfo result)
        // {
        // }

        public unsafe static void Create(LobbyTypeEnum lobbyType, int maxMembers, CompletedDelegate <Lobby> callback)
        {
        }