Example #1
0
        private static void DoWork()
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(DoCleanShutdown);

            Settings.rvSettings = new Settings();

            _thWrk = new ThreadWorker(StartUpCode)
            {
                wReport = BgwProgressChanged
            };
            _thWrk.Start();
            Console.WriteLine("");
            Console.WriteLine("");

            if (doUpdateDATs)
            {
                _thWrk = new ThreadWorker(DatUpdate.UpdateDat)
                {
                    wReport = BgwProgressChanged
                };
                _thWrk.Start();
                Console.WriteLine("");
                Console.WriteLine("");
            }

            if (doScanROMs)
            {
                FileScanning.StartAt    = null;
                FileScanning.EScanLevel = EScanLevel.Level2;
                _thWrk = new ThreadWorker(FileScanning.ScanFiles)
                {
                    wReport = BgwProgressChanged
                };
                _thWrk.Start();
                Console.WriteLine("");
                Console.WriteLine("");
            }

            if (doFindFixes)
            {
                _thWrk = new ThreadWorker(FindFixes.ScanFiles)
                {
                    wReport = BgwProgressChanged
                };
                _thWrk.Start();
                Console.WriteLine("");
                Console.WriteLine("");
            }

            if (doFixROMs)
            {
                _thWrk = new ThreadWorker(Fix.PerformFixes)
                {
                    wReport = BgwProgressChanged
                };
                _thWrk.Start();
                Console.WriteLine("");
                Console.WriteLine("");
            }
        }
Example #2
0
 public void Start()
 {
     if (Status == TaskStatus.InQueue && !IsStopped)
     {
         Prepare();
         threadWorker            = new ThreadWorker();
         threadWorker.DoWork    += ThreadDoWork;
         threadWorker.Completed += ThreadCompleted;
         threadWorker.Start(ApartmentState.STA);
     }
 }
Example #3
0
    /// <summary>
    /// Pings a PlayFab server by url for QoS metrics
    /// </summary>
    /// <param name="serverUrl"></param>
    public void Ping(string serverUrl)
    {
        byte firstByte  = 255;
        byte secondByte = 255;

        Byte[] datagram = { firstByte, secondByte };

        ThreadWorker worker = new ThreadWorker();

        worker.Start(UdpQoSClient.Ping(serverUrl, udpPort, datagram));
    }
Example #4
0
        public void ThreadWorker_ProofOfConcept()
        {
            var finalOutput = new List <string>();
            var bkg         = new ThreadWorker <int, string>();

            bkg.Start(_DoBkgWork);
            bkg.OutputResults.DataReceived += _OnOutputDataReceived;

            bkg.InputToProcess.Add(5);
            bkg.InputToProcess.Add(1088050);

            bkg.InputToProcess.Add(1010155001);

            bkg.ShutdownGracefullyAndWaitForCompletion().ContinueWith(_ =>
            {
                Assert.IsFalse(bkg.IsActive);
                string result = String.Join(",", finalOutput);
                Assert.AreEqual("5,1,88,5,1,1,155,1", result);
            });

            void _DoBkgWork(ThreadWorkerDataTracker <int, TNone, string> data)
            {
                while (data.ShouldContinue || data.InputToProcess.Any())
                {
                    if (!data.InputToProcess.Any())
                    {
                        _Yield();
                        continue;
                    }

                    // Grab the input state
                    int number = data.InputToProcess.TakeNext();

                    // Process
                    List <string> output = new List <string>();
                    output.AddRange(number.ToString().Split(new[] { '0' }, StringSplitOptions.RemoveEmptyEntries));

                    // Set the output state
                    data.OutputResults.AddRange(output);
                    data.OutputResults.NotifyDataReceived();
                    _Yield();
                }

                void _Yield()
                {
                    Thread.Sleep(0);
                }
            }

            void _OnOutputDataReceived(object sender, EventArgs e)
            {
                finalOutput.AddRange(bkg.OutputResults.TakeAll());
            }
        }
Example #5
0
        public void Start()
        {
            if (Status == TaskStatus.InQueue && !StopRequested)
            {
                Info.TaskStartTime = DateTime.Now;

                threadWorker = new ThreadWorker();
                Prepare();
                threadWorker.DoWork    += ThreadDoWork;
                threadWorker.Completed += ThreadCompleted;
                threadWorker.Start(ApartmentState.STA);
            }
        }
Example #6
0
        public void ThreadWorker_ExecutionState_Test()
        {
            var finalOutput = new List <string>();
            var bkg         = new ThreadWorker <int, char, string>();

            // Split all incoming numbers on 0 & 5
            bkg.ExecutionState.Add('0');
            bkg.ExecutionState.Add('5');
            bkg.Start(_DoBkgWork);

            bkg.OutputResults.DataReceived += _OnOutputDataReceived;

            bkg.InputToProcess.Add(5);
            bkg.InputToProcess.Add(1088050);
            bkg.ShutdownGracefullyAndWaitForCompletion().ContinueWith(_ =>
            {
                Assert.IsFalse(bkg.IsActive);
                string result = String.Join(",", finalOutput);
                Assert.AreEqual("1,88", result);
            });

            void _DoBkgWork(ThreadWorkerDataTracker <int, char, string> data)
            {
                while (data.ShouldContinue || data.InputToProcess.Any())
                {
                    if (!data.InputToProcess.Any())
                    {
                        Thread.Sleep(0);
                        continue;
                    }

                    // Grab the input state
                    int    number  = data.InputToProcess.TakeNext();
                    char[] splitOn = data.ExecutionState.ToArray();

                    // Process
                    List <string> output = new List <string>();
                    output.AddRange(number.ToString().Split(splitOn, StringSplitOptions.RemoveEmptyEntries));

                    // Set the output state
                    data.OutputResults.AddRange(output);
                    data.OutputResults.NotifyDataReceived();
                    Thread.Sleep(0);
                }
            }

            void _OnOutputDataReceived(object sender, EventArgs e)
            {
                finalOutput.AddRange(bkg.OutputResults.TakeAll());
            }
        }
Example #7
0
        public static void AnnotateImageAsync(Bitmap bmp, string filePath, TaskSettings taskSettings)
        {
            ThreadWorker worker = new ThreadWorker();

            worker.DoWork += () =>
            {
                bmp = AnnotateImage(bmp, filePath, taskSettings);
            };

            worker.Completed += () =>
            {
                if (bmp != null)
                {
                    //UploadManager.RunImageTask(bmp, taskSettings);
                }
            };

            worker.Start(ApartmentState.STA);
        }