private ExceptionReportsManager()
 {
     backgroundWork = new AbortableBackgroundWorker();
     backgroundWork.DoWork += backgroundWork_DoWork;
     backgroundWork.RunWorkerCompleted += backgroundWork_RunWorkerCompleted;
     view = new ExceptionReportForm();
     view.Closed += view_Closed;
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.domain_UnhandledException);
     Application.ThreadException += new ThreadExceptionEventHandler(this.application_ThreadException);
     try
     {
         IPAddress[] hostAddresses = Dns.GetHostAddresses(Dns.GetHostName());
         if (hostAddresses.Length > 0)
         {
             this.hostAddress = new string[hostAddresses.Length];
             for (int i = 0; i < hostAddresses.Length; i++)
             {
                 this.hostAddress[i] = hostAddresses[i].ToString();
             }
         }
         else
         {
             this.hostAddress = new string[] { "无本机IP。" };
         }
     }
     catch
     {
         this.hostAddress = new string[] { "获取本机IP失败。" };
     }
     this.config = null;
 }
Пример #2
0
 private void _WorkerAbort(ref AbortableBackgroundWorker worker)
 {
     if (worker != null)
     {
         worker.Abort();
         worker = null;
         Thread.Sleep(100);
         Progress.Visible     = false;
         CancelWorker.Visible = false;
     }
 }
Пример #3
0
        private void SetupCallback()
        {
            SetParameterInt("IP_EventOnAvailableValues", 1);
            SensorCommand("DataAvail_Event");
            _hSensorDataReady = GetParameterDWORD("IA_DataAvailEvent");

            if (_hSensorDataReady != 0)
            {
                _bw = new AbortableBackgroundWorker()
                {
                    WorkerSupportsCancellation = true
                };
                _bw.DoWork += new DoWorkEventHandler(WaitForData);
            }
        }
Пример #4
0
        private Result _WorkerInit(ref AbortableBackgroundWorker worker)
        {
            _WorkerAbort(ref worker);
            worker = new AbortableBackgroundWorker();
            worker.WorkerReportsProgress = true;
            // You have to set cancellation manually. Default is now abortion:
            worker.WorkerSupportsCancellation = true;
            worker.RunWorkerCompleted        += _WorkerCompleted;
            worker.ProgressChanged           += _WorkerProgressChanged;

            Progress.Visible     = true;
            CancelWorker.Visible = true;

            TimeOpSmooth.Clear();

            return(new Result(Status.Ok));
        }
Пример #5
0
        public Bot(FlatListBox logLB)
        {
            //Attach Bluestacks process
            if (BotProcess.ProcessExist("HD-Frontend"))
            {
                bs = new BotProcess("HD-Frontend");
            }
            else
            {
                MessageBox.Show("Bluestacks is not open, please start it and restart the bot.");
                Environment.Exit(0);
            }

            //Set the default state
            botState = BotState.Free;

            //Set the listbox log
            logListBox = logLB;

            //Create the config
            cfgParser = new FileIniDataParser();

            //Worker configuration
            botWorker         = new AbortableBackgroundWorker();
            botWorker.DoWork += botWorker_DoWork;
            botWorker.WorkerSupportsCancellation = true;

            //JS engine configuration
            js = new Engine(cfg => cfg.AllowClr()).SetValue("BotMouse", bs.mouse)
                 .SetValue("BotKeyboard", bs.keyboard)
                 .SetValue("BotImage", bs.image)
                 .SetValue("BotWindow", bs.window)
                 .SetValue("Config", cfgData)
                 .SetValue("Bot", this);

            //Load the config
            ReloadConfig();
        }
Пример #6
0
        /// <summary>
        /// Destroy this component
        /// </summary>
        public override void Destroy()
        {
            base.Destroy();  // Sets IsDestroying flag

            try
            {
                if (_iSensor != 0)
                {
                    if (_hSensorDataReady != 0)
                    {
                        // Complete worker thread
                        MEDAQLibDLL.SetEvent(_hSensorDataReady);
                        Thread.Sleep(50);
                    }
                    MEDAQLibDLL.CloseSensor(_iSensor);
                    MEDAQLibDLL.ReleaseSensorInstance(_iSensor);
                }
                if (_bw != null)
                {
                    if (_bw.IsBusy)
                    {
                        _bw.CancelAsync();
                    }
                    _bw.Dispose();
                    _bw = null;
                }
            }
            catch (Exception ex)
            {
                U.LogError(ex, "Error disposing '{0}'", Nickname);
            }
            finally
            {
                _bw = null;
            }
        }
 public PartTaskProgressReport(AbortableBackgroundWorker src)
     : base(src)
 {
     _src = src;
 }
Пример #8
0
        private void btn_Start_Click(object sender, EventArgs e)
        {
            btn_Start.Text = "Stop Ping";
              btn_Start.Click -= btn_Start_Click;
              btn_Start.Click += btn_Stop_Click;
              tb_Result.Clear();

              bw = new AbortableBackgroundWorker();

              // this allows our worker to report progress during work
              bw.WorkerReportsProgress = true;

              // what to do in the background thread
              bw.DoWork += new DoWorkEventHandler(
              delegate(object o, DoWorkEventArgs args)
              {
            BackgroundWorker b = o as BackgroundWorker;

            // run ping() in an endless loop
            while (true)
            {
              b.ReportProgress(10, ping());
              Thread.Sleep(Convert.ToInt32(tb_Interval.Text));
            }

              });

              // what to do when progress changed (update the progress bar for example)
              bw.ProgressChanged += new ProgressChangedEventHandler(
              delegate(object o, ProgressChangedEventArgs args)
              {
            tb_Result.AppendText(string.Format("{0}", args.UserState));// = string.Format("{0}% Completed", args.ProgressPercentage);
            if (b_writeToFile)
              tw.Write(string.Format("{0}", args.UserState));
              });

              bw.RunWorkerAsync();
        }
Пример #9
0
        public void Sync_Requested(object sender = null, EventArgs e = null)
        {
            ManualForceCompare = false;
            if (sender != null && sender.GetType().ToString().EndsWith("Timer")) { //Automated sync
                NotificationTray.UpdateItem("delayRemove", enabled: false);
                if (bSyncNow.Text == "Start Sync") {
                    log.Info("Scheduled sync started.");
                    Timer aTimer = sender as Timer;
                    if (aTimer.Tag.ToString() == "PushTimer") sync_Start(updateSyncSchedule: false);
                    else if (aTimer.Tag.ToString() == "AutoSyncTimer") sync_Start(updateSyncSchedule: true);
                } else if (bSyncNow.Text == "Stop Sync") {
                    log.Warn("Automated sync triggered whilst previous sync is still running. Ignoring this new request.");
                    if (bwSync == null)
                        log.Debug("Background worker is null somehow?!");
                    else
                        log.Debug("Background worker is busy? A:" + bwSync.IsBusy.ToString());
                }

            } else { //Manual sync
                if (bSyncNow.Text == "Start Sync") {
                    log.Info("Manual sync started.");
                    if (Control.ModifierKeys == Keys.Shift) { ManualForceCompare = true; log.Info("Shift-click has forced a compare of all items"); }
                    sync_Start(updateSyncSchedule: false);

                } else if (bSyncNow.Text == "Stop Sync") {
                    if (bwSync != null && !bwSync.CancellationPending) {
                        log.Warn("Sync cancellation requested.");
                        bwSync.CancelAsync();
                    } else {
                        Logboxout("Repeated cancellation requested - forcefully aborting thread!");
                        try {
                            bwSync.Abort();
                            bwSync.Dispose();
                            bwSync = null;
                        } catch { }
                    }
                }
            }
        }
Пример #10
0
        private void sync_Start(Boolean updateSyncSchedule = true)
        {
            LogBox.Clear();

            if (Settings.Instance.UseGoogleCalendar == null ||
                Settings.Instance.UseGoogleCalendar.Id == null ||
                Settings.Instance.UseGoogleCalendar.Id == "") {
                MessageBox.Show("You need to select a Google Calendar first on the 'Settings' tab.");
                return;
            }
            //Check network availability
            if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) {
                Logboxout("There does not appear to be any network available! Sync aborted.", notifyBubble: true);
                return;
            }
            //Check if Outlook is Online
            try {
                if (OutlookCalendar.Instance.IOutlook.Offline() && Settings.Instance.AddAttendees) {
                    Logboxout("You have selected to sync attendees but Outlook is currently offline.");
                    Logboxout("Either put Outlook online or do not sync attendees.", notifyBubble: true);
                    return;
                }
            } catch (System.Exception ex) {
                Logboxout(ex.Message, notifyBubble: true);
                log.Error(ex.StackTrace);
                return;
            }
            GoogleCalendar.APIlimitReached_attendee = false;
            MainForm.Instance.syncNote(SyncNotes.QuotaExhaustedInfo, null, false);
            bSyncNow.Text = "Stop Sync";
            NotificationTray.UpdateItem("sync", "&Stop Sync");

            String cacheNextSync = lNextSyncVal.Text;
            lNextSyncVal.Text = "In progress...";

            DateTime SyncStarted = DateTime.Now;
            log.Info("Sync version: " + System.Windows.Forms.Application.ProductVersion);
            Logboxout("Sync started at " + SyncStarted.ToString());
            Logboxout("Syncing from " + Settings.Instance.SyncStart.ToShortDateString() +
                " to " + Settings.Instance.SyncEnd.ToShortDateString());
            Logboxout(Settings.Instance.SyncDirection.Name);
            Logboxout("--------------------------------------------------");

            if (Settings.Instance.OutlookPush) OutlookCalendar.Instance.DeregisterForPushSync();

            Boolean syncOk = false;
            int failedAttempts = 0;
            Social.TrackSync();
            GoogleCalendar.Instance.GetCalendarSettings();
            while (!syncOk) {
                // DJS - Suppress annoying MsgBox when we're offline
                if (failedAttempts > 0 &&
                    MessageBox.Show("The synchronisation failed - check the Sync tab for further details.\r\nDo you want to try again?", "Sync Failed",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
                //if (failedAttempts > 0)
                {
                    bSyncNow.Text = "Start Sync";
                    NotificationTray.UpdateItem("sync", "&Sync Now");
                    break;
                }

                //Set up a separate thread for the sync to operate in. Keeps the UI responsive.
                bwSync = new AbortableBackgroundWorker();
                //Don't need thread to report back. The logbox is updated from the thread anyway.
                bwSync.WorkerReportsProgress = false;
                bwSync.WorkerSupportsCancellation = true;

                //Kick off the sync in the background thread
                bwSync.DoWork += new DoWorkEventHandler(
                    delegate(object o, DoWorkEventArgs args) {
                        BackgroundWorker b = o as BackgroundWorker;
                        try {
                            syncOk = synchronize();
                        } catch (System.Exception ex) {
                            MainForm.Instance.Logboxout("The following error was encountered during sync:-");
                            MainForm.Instance.Logboxout(ex.Message, notifyBubble: true);
                            log.Error(ex.StackTrace);
                            syncOk = false;
                        }
                    }
                );

                bwSync.RunWorkerAsync();
                while (bwSync != null && (bwSync.IsBusy || bwSync.CancellationPending)) {
                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(100);
                }
                try {
                    //Get Logbox text - this is a little bit dirty!
                    if (!syncOk && LogBox.Text.Contains("The RPC server is unavailable.")) {
                        Logboxout("Attempting to reconnect to Outlook...");
                        try { OutlookCalendar.Instance.Reset(); } catch { }
                    }
                } finally {
                    failedAttempts += !syncOk ? 1 : 0;
                }
            }
            Settings.Instance.CompletedSyncs += syncOk ? 1 : 0;
            bSyncNow.Text = "Start Sync";
            NotificationTray.UpdateItem("sync", "&Sync Now");

            Logboxout(syncOk ? "Sync finished with success!" : "Operation aborted after " + failedAttempts + " failed attempts!");

            if (Settings.Instance.OutlookPush) OutlookCalendar.Instance.RegisterForPushSync();

            lLastSyncVal.Text = SyncStarted.ToLongDateString() + " - " + SyncStarted.ToLongTimeString();
            Settings.Instance.LastSyncDate = SyncStarted;
            if (!updateSyncSchedule) {
                lNextSyncVal.Text = cacheNextSync;
            } else {
                if (syncOk) {
                    OgcsTimer.LastSyncDate = SyncStarted;
                    OgcsTimer.SetNextSync();
                } else {
                    if (Settings.Instance.SyncInterval != 0) {
                        Logboxout("Another sync has been scheduled to automatically run in 5 minutes time.");
                        OgcsTimer.SetNextSync(5, fromNow: true);
                    }
                }
            }
            bSyncNow.Enabled = true;
            if (OutlookCalendar.Instance.OgcsPushTimer != null)
                OutlookCalendar.Instance.OgcsPushTimer.ItemsQueued = 0; //Reset Push flag regardless of success (don't want it trying every 2 mins)

            checkSyncMilestone(); // DJS - annoying MsgBox ahead!
        }
Пример #11
0
 private void RunManual_OnClick(object sender, RoutedEventArgs e)
 {
     bw = new AbortableBackgroundWorker();
     bw.DoWork += BackgroundMakeManual;
     bw.RunWorkerCompleted += bw_RunWorkerCompleted;
     Progress.Visibility = Visibility.Visible;
     ConfigBox.IsEnabled = false;
     AbortButton.Visibility = Visibility.Visible;
     bw.RunWorkerAsync();
 }
Пример #12
0
 //процедура создания цикла скачивания
 public void Processing(bool get_immediately=false)
 {
     ap = new apartments();
     work = true;
     //t_fill.Start();
     //t_restart.Start();
     for (int i = 0; i < max_threads; i++)
     {
         try
         {
             bws[i] = new AbortableBackgroundWorker();
             /*bws[i].DoWork += new DoWorkEventHandler(Worker);
             bws[i].RunWorkerAsync(i);*/
         }
         catch (Exception ex) { ddbs.WriteErrorMessage(ddbs.ConnectionString, i, null, "ошибка создания worker'а " + ex.Message); }
                             
     }
     BackgroundWorker bw = new BackgroundWorker();
     bw.DoWork += new DoWorkEventHandler(NewWorker);
     bw.RunWorkerAsync();
 }
Пример #13
0
 public TaskProgressReport(AbortableBackgroundWorker src)
 {
     _src = src;
 }
Пример #14
0
        private void startStopButton_Click(object sender, RoutedEventArgs e) {
            if (worker != null && worker.IsBusy) {
                Trace.WriteLine("Aborting...");
                worker.Abort();
                return;
            }

            var p = new Parameters {
                InputPath = inputPathTextBox.Text,
                OutputPath = outputPathTextBox.Text,
                ExtractTracks = (bool)extractTracksCheckBox.IsChecked,
                PreserveChapters = (bool)preserveChaptersCheckBox.IsChecked
            };

            p.Titles.AddRange(SelectedTitles);
            p.Tracks.AddRange(Tracks.Where(x => x.IsUsed));

            using (worker = new AbortableBackgroundWorker()) {
                worker.DoWork += (s, args) => {
                    var xin1Generator = new Xin1Generator.Xin1Generator(p);
                    xin1Generator.GenerateAll();
                };
                worker.RunWorkerCompleted += (s, args) => {
                    if (args.Error != null)
                        Trace.WriteLine(string.Format(
                            Xin1Generator.Properties.Resources.ErrorMessage,
                            args.Error.Message));
                    else if (args.Cancelled)
                        Trace.WriteLine("Aborted");
                    else
                        Trace.WriteLine("Completed");

                    UpdateStartStopButton();
                };
                worker.RunWorkerAsync();
            }

            UpdateStartStopButton();
        }