Пример #1
0
        private void BkgWorkerStartStopSync_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var progress = (SyncStartStopProgress)e.UserState;

            UpdateButtonCallback updBtnCb = (button, text, enabled) =>
            {
                button.Text    = text;
                button.Enabled = enabled;
            };

            ToggleControlsEnabledCallback toggleEnabledCb = (enabled) => ToggleControlsEnabled(enabled);

            switch (progress)
            {
            case SyncStartStopProgress.STARTING:
                ToggleControlsEnabled(false);

                BtnStartStop.Enabled = false;
                BtnStartStop.Text    = L10n.Get("AppStarting");

                NotifyIconContextMenuItemStartStop.Enabled = false;
                NotifyIconContextMenuItemStartStop.Text    = L10n.Get("AppStarting");

                break;

            case SyncStartStopProgress.STOPPING:
                this.Invoke(toggleEnabledCb, new object[] { false });
                this.Invoke(updBtnCb, new object[] { BtnStartStop, L10n.Get("AppStopping"), false });

                NotifyIconContextMenuItemStartStop.Enabled = false;
                NotifyIconContextMenuItemStartStop.Text    = L10n.Get("AppStopping");

                break;

            case SyncStartStopProgress.STARTED:
                BtnStartStop.Enabled = true;
                BtnStartStop.Text    = L10n.Get("AppStop", AppName);

                NotifyIconContextMenuItemStartStop.Enabled = true;
                NotifyIconContextMenuItemStartStop.Text    = L10n.Get("MenuAppStop", AppName);

                Hide();

                break;

            case SyncStartStopProgress.STOPPED:
                this.Invoke(toggleEnabledCb, new object[] { true });
                this.Invoke(updBtnCb, new object[] { BtnStartStop, L10n.Get("AppStart", AppName), true });

                NotifyIconContextMenuItemStartStop.Enabled = true;
                NotifyIconContextMenuItemStartStop.Text    = L10n.Get("MenuAppStart", AppName);

                break;
            }
        }
Пример #2
0
 private void SetText(Button button, string text)
 {
     if (button.InvokeRequired)
     {
         var d = new UpdateButtonCallback(SetText);
         button.Invoke(d, new object[] { button, text });
     }
     else
     {
         button.Text = text;
     }
 }
Пример #3
0
        public static void UpdateButton(Button btn, string text)
        {
            if (text == null)
            {
                return;
            }

            try {
                if (btn.InvokeRequired)
                {
                    UpdateButtonCallback d = UpdateButton;
                    btn.Invoke(d, btn, text);
                    return;
                }

                btn.Text = text;
            }
            catch {
                // This catch is simply here to avoid the OCCASIONAL crash of the application when closing it by pressing the stop button in visual studio while it is running tasks
            }
        }