public static void InvokeOperation(this Control TargetControl, ThreadOperation o)
 {
     if (TargetControl.InvokeRequired)
     TargetControl.Invoke((Delegate) new ControlExtension.InvokeOperationDelegate(ControlExtension.InvokeOperation), (object) TargetControl, (object) o);
       else
     o();
 }
示例#2
0
        private static void DispatchOperations()
        {
            ThreadOperation operation = _ops.Dequeue();

            if (operation == null)
            {
                return;
            }
            Mixpanel.Log($"Dispatching new operation: {operation.GetAction()}");
            Value data = operation.GetWhat();

            switch (operation.GetAction())
            {
            case ThreadOperation.ThreadOperationAction.ENQUEUE_EVENTS:
                MixpanelStorage.TrackPersistentQueue.Enqueue(data);
                break;

            case ThreadOperation.ThreadOperationAction.ENQUEUE_PEOPLE:
                MixpanelStorage.EngagePersistentQueue.Enqueue(data);
                break;

            case ThreadOperation.ThreadOperationAction.FLUSH:
                if (_isBgThreadRunning)
                {
                    IEnumerator trackEnum  = SendData(MixpanelStorage.TrackPersistentQueue, Config.TrackUrl);
                    IEnumerator engageEnum = SendData(MixpanelStorage.EngagePersistentQueue, Config.EngageUrl);
                    while (trackEnum.MoveNext())
                    {
                    }
                    ;
                    while (engageEnum.MoveNext())
                    {
                    }
                    ;
                }
                else
                {
                    Controller.GetInstance().StartCoroutine(SendData(MixpanelStorage.TrackPersistentQueue, Config.TrackUrl));
                    Controller.GetInstance().StartCoroutine(SendData(MixpanelStorage.EngagePersistentQueue, Config.EngageUrl));
                }

                break;

            case ThreadOperation.ThreadOperationAction.CLEAR_QUEUE:
                MixpanelStorage.TrackPersistentQueue.Clear();
                MixpanelStorage.EngagePersistentQueue.Clear();
                break;

            case ThreadOperation.ThreadOperationAction.KILL_THREAD:
                _isBgThreadRunning = false;
                _bgThread.Abort();     // Will throw an exception
                break;

            default:
                break;
            }
        }
示例#3
0
 public static void PerformOperation(IWin32Window Owner, ThreadOperation o, bool WaitForNext, string LoadingText, int? ProgressMaxValue, EventHandler CancelHandler, Action SuccessHandler)
 {
     bool result = false;
       ThreadWorker.lastText = LoadingText;
       ThreadWorker.lastWait = WaitForNext;
       LoadingForm.ShowBlockingLoading(Owner, WaitForNext, LoadingText, ProgressMaxValue, CancelHandler);
       Exception exception = (Exception) null;
       Thread th = (Thread) null;
       EventHandler canceller = (EventHandler) ((ls, le) =>
       {
     LoadingForm.HideBlockingLoading();
     th.Abort();
     if (CancelHandler == null)
       return;
     CancelHandler((object) null, new EventArgs());
       });
       ThreadOperation finalizer = (ThreadOperation) (() =>
       {
     LoadingForm.HideBlockingLoading();
     LoadingForm.Cancel -= canceller;
     if (exception != null && !exception.Message.Contains("request was aborted") && !(exception is UserException))
     {
       int temp_93 = (int) new BigMessageBoxForm("Ошибка", string.Format("Type:\r\n{0}\r\n\r\nMessage:\r\n{1}\r\n\r\nStackTrace:\r\n{2}", (object) exception.GetType(), (object) exception.Message, (object) exception.StackTrace)).ShowDialog(Owner);
     }
     if (exception != null && exception is UserException)
     {
       int temp_68 = (int) MessageBox.Show(Owner, exception.Message, "Ошибка");
     }
     if (!result)
       return;
     SuccessHandler();
       });
       th = new Thread((ThreadStart) (() =>
       {
     try
     {
       o();
       result = true;
     }
     catch (ThreadAbortException exception_0)
     {
     }
     catch (Exception exception_1)
     {
     }
     if (Owner != null && Owner is Form)
       ControlExtension.InvokeOperation((Control) (Owner as Form), finalizer);
     else
       finalizer();
       }));
       LoadingForm.Cancel += canceller;
       th.Start();
 }
示例#4
0
 public static Action PerformSimpleOperation(Form Owner, ThreadOperation o, Action onEnd)
 {
     bool result = true;
       Exception exception = (Exception) null;
       Thread th = new Thread((ThreadStart) (() =>
       {
       try
       {
       o();
       }
       catch (ThreadAbortException exception_0)
       {
       }
       catch (Exception exception_1)
       {
       result = false;
       ControlExtension.InvokeOperation((Control) Owner, (ThreadOperation) (() =>
           {
               if (exception_1 != null && !exception_1.Message.Contains("request was aborted") && !(exception_1 is UserException))
                   throw exception_1;
               if (exception_1 != null && exception_1 is UserException)
               {
                   int temp_58 = (int) MessageBox.Show((IWin32Window) Owner, exception_1.Message, "Ошибка");
                   result = false;
               }
               if (!result)
                   return;
               if (onEnd == null)
                   return;
               try
               {
                   onEnd();
               }
               catch (Exception exception_2)
               {
                   int temp_48 = (int) MessageBox.Show((IWin32Window) Owner, exception_2.Message, "Ошибка");
               }
           }));
       }
       }));
       th.Start();
       return (Action) (() =>
       {
     if (th == null)
       return;
     th.Abort();
       });
 }