Example #1
0
        private static void RunControlRunner(MainForm form, string[] args)
        {
            Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
            Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
            var uir = new ControlRunner(form, (ex) =>
            {
                Console.WriteLine(ex.Message);
                throw new Exception("Should be ignored");
            });
            var ior = new ThreadRunner("Runner");

            ior.Run(() =>
            {
                Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
                Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
                uir.Run(() => { throw new Exception("Should be catched"); });
                uir.Run(() =>
                {
                    Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
                    Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
                    Console.WriteLine("form.Text {0}", form.Text);
                    form.Close();
                });
            });
        }
Example #2
0
        public void Impersonate_Anonymous_GetThreadToken(bool openAsSelf)
        {
            using (var token = Security.OpenProcessToken(AccessTokenRights.Read))
            {
                var privileges = token.GetTokenPrivileges();
            }

            ThreadRunner.Run((() =>
            {
                Security.ImpersonateAnonymousToken();
                SID sid;
                using (var threadToken = Security.OpenThreadToken(AccessTokenRights.Query, openAsSelf))
                {
                    threadToken.Should().NotBeNull();
                    threadToken.IsInvalid.Should().BeFalse();
                    sid = threadToken.GetTokenOwnerSid();
                    Action action = () => sid.LookupAccountSid();
                    action.Should().Throw <UnauthorizedAccessException>();

                    var privileges = threadToken.GetTokenPrivileges();
                }
                Security.RevertToSelf();

                var info = sid.LookupAccountSid();
                info.Name.Should().Be("ANONYMOUS LOGON");
                info.Usage.Should().Be(SidNameUse.WellKnownGroup);
                sid.Equals(Security.CreateWellKnownSid(WellKnownSID.Anonymous)).Should().BeTrue();
            }));
        }
    public static int CreateThread(ParameterizedThreadStart pThreadStart, object LoadData)
    {
        ThreadedTask newTask = new ThreadedTask(pThreadStart, LoadData);

        ThreadRunner.AddThread(newTask);
        return(newTask.ManagedThreadId);
    }
        public void Impersonate_DisableUserAddGroup_FileAccess()
        {
            ThreadRunner.Run((() =>
            {
                using (var cleaner = new TestFileCleaner())
                    using (var token = Security.OpenProcessToken(AccessTokenRights.Duplicate | AccessTokenRights.Query))
                    {
                        string path = cleaner.CreateTestFile(nameof(Impersonate_DisableUser_FileAccess));
                        FileHelper.ReadAllText(path).Should().Be(nameof(Impersonate_DisableUser_FileAccess));

                        // Add Users group
                        using (var handle = Storage.CreateFile(path, CreationDisposition.OpenExisting,
                                                               DesiredAccess.GenericReadWrite | DesiredAccess.WriteDac))
                        {
                            handle.IsInvalid.Should().BeFalse();
                            SID usersGroup = Security.CreateWellKnownSid(WellKnownSID.Users);
                            handle.ChangeAccess(usersGroup, FileAccessRights.GenericRead, AccessMode.Grant);
                        }

                        // Disable the primary user token (prevents using for granting access)
                        using (var restricted = Security.CreateRestrictedToken(token, Security.GetTokenUserSid(token)))
                        {
                            Security.ImpersonateLoggedOnUser(restricted);

                            // We'll get access through the Users group
                            FileHelper.ReadAllText(path).Should().Be(nameof(Impersonate_DisableUser_FileAccess));

                            Security.RevertToSelf();
                            FileHelper.ReadAllText(path).Should().Be(nameof(Impersonate_DisableUser_FileAccess));
                        }
                    }
            }));
        }
Example #5
0
        public void SetAndGet_Current_Threading()
        {
            User user = User.FindByUserName("substituting.user");

            var principal = CreateSecurityManagerPrincipal(user.Tenant, user, null);

            SecurityManagerPrincipal.Current = principal;
            Assert.That(SecurityManagerPrincipal.Current, Is.SameAs(principal));

            ThreadRunner.Run(
                delegate
            {
                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                {
                    User otherUser     = User.FindByUserName("group1/user1");
                    var otherPrincipal = CreateSecurityManagerPrincipal(otherUser.Tenant, otherUser, null);

                    Assert.That(SecurityManagerPrincipal.Current.IsNull, Is.True);
                    SecurityManagerPrincipal.Current = otherPrincipal;
                    Assert.That(SecurityManagerPrincipal.Current, Is.SameAs(otherPrincipal));
                }
            });

            Assert.That(SecurityManagerPrincipal.Current, Is.SameAs(principal));
        }
Example #6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    webView.NeedClientCertificate -= WebView_NeedClientCertificate;
                    webView.CertificateError      -= WebView_CertificateError;
                    webView.LoadCompleted         -= WebView_LoadCompleted;
                    webView.LoadFailed            -= WebView_LoadFailed;

                    threadRunner.Dispose();
                    threadRunner = null;

                    webView.Dispose();
                    webView = null;

                    engine.Stop(true);
                    engine = null;

                    _semaphoreSlim.Dispose();
                    _semaphoreSlim = null;

                    WriteLog(" ***** Destroyed ***** ");
                }

                disposedValue = true;
            }
        }
        public void AddUser_AnonymousRead_CanRead()
        {
            using (var cleaner = new TestFileCleaner())
            {
                string path = cleaner.CreateTestFile(nameof(AddUser_AnonymousRead_CanRead));

                using (var handle = Storage.CreateFile(path, CreationDisposition.OpenExisting,
                                                       DesiredAccess.GenericReadWrite | DesiredAccess.WriteDac))
                {
                    handle.IsInvalid.Should().BeFalse();
                    SID anonymous = Security.CreateWellKnownSid(WellKnownSID.Anonymous);
                    handle.ChangeAccess(anonymous, FileAccessRights.GenericRead, AccessMode.Grant);
                }

                ThreadRunner.Run(() =>
                {
                    Security.ImpersonateAnonymousToken();
                    Action action = () => FileHelper.ReadAllText(path);
                    // The problem here is that Anonymous does not have bypass traverse checking.
                    // All folders, including the root, would need to have DirectoryAccessRights.Traverse.
                    action.Should().Throw <UnauthorizedAccessException>();
                    Security.RevertToSelf();
                });
            }
        }
        /// <summary>
        /// A common helper method that tests running a test in an apartment from an apartment.
        /// </summary>
        private bool RunInApartmentFromApartment(ApartmentState fromApartMent, ApartmentState inApartment)
        {
            bool wasRunInCorrectApartment = false;

            Thread runnerThread = new Thread((ThreadStart) delegate
            {
                if (inApartment == ApartmentState.MTA)
                {
                    ThreadRunner.RunInMTA(delegate
                    {
                        wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
                    });
                }
                else if (inApartment == ApartmentState.STA)
                {
                    ThreadRunner.RunInSTA(delegate
                    {
                        wasRunInCorrectApartment = Thread.CurrentThread.GetApartmentState() == inApartment;
                    });
                }
            }
                                             );

            runnerThread.SetApartmentState(fromApartMent);
            runnerThread.Start();
            runnerThread.Join();

            return(wasRunInCorrectApartment);
        }
Example #9
0
        private void Init(string url = null)
        {
            engine = Engine.Create(id);
            engine.Options.AllowProprietaryMediaFormats();
            engine.Options.CachePath = $"{id}";

            threadRunner = new ThreadRunner(ID, engine);

            BrowserOptions options = new BrowserOptions()
            {
                AllowJavaScript = true,
                AllowPlugins    = true,
                AllowJavaScriptAccessClipboard = true,
                AllowJavaScriptCloseWindow     = true,
                AllowJavaScriptDOMPaste        = true,
                AllowZooming = true,
            };

            webView = threadRunner.CreateWebView(defaultSize.Width, defaultSize.Height, options);
            webView.CustomUserAgent = userAgent;

            webView.NeedClientCertificate += WebView_NeedClientCertificate;
            webView.CertificateError      += WebView_CertificateError;
            webView.LoadCompleted         += WebView_LoadCompleted;
            webView.LoadFailed            += WebView_LoadFailed;

            if (!String.IsNullOrEmpty(url))
            {
                TargetUrl = url;
                UrlAsync  = url;
                UpdateCurrentUrl(url);
            }

            WriteLog($"Initialized: ID: {id} Cache: {engine.CachePath} Window Size: {defaultSize}");
        }
Example #10
0
        public void EncryptFile_DisableRightsBeforeEncrypting()
        {
            ThreadRunner.Run((() =>
            {
                using (var cleaner = new TestFileCleaner())
                    using (var token = Security.OpenProcessToken(AccessTokenRights.Duplicate | AccessTokenRights.Query | AccessTokenRights.Impersonate))
                    {
                        // Create and encrypt the file
                        string path = cleaner.CreateTestFile(nameof(EncryptFile_DisableRightsBeforeEncrypting));

                        Action action;

                        // Disable the primary user token (prevents using for granting access)
                        using (var restricted = Security.CreateRestrictedToken(token, Security.GetTokenUserSid(token)))
                        {
                            Security.ImpersonateLoggedOnUser(restricted);
                            action = () => Storage.EncryptFile(path);
                            action.Should().Throw <UnauthorizedAccessException>();
                            Security.RevertToSelf();
                        }

                        action = () => Storage.QueryUsersOnEncryptedFile(path);
                        action.Should().Throw <WInteropIOException>()
                        .And.HResult.Should().Be((int)WindowsError.ERROR_FILE_NOT_ENCRYPTED.ToHResult());
                    }
            }));
        }
Example #11
0
        public void EncryptFile_DisableRightsAfterEncrypting()
        {
            ThreadRunner.Run((() =>
            {
                using (var cleaner = new TestFileCleaner())
                    using (var token = Security.OpenProcessToken(AccessTokenRights.Duplicate | AccessTokenRights.Query))
                    {
                        // Create and encrypt the file
                        string path = cleaner.CreateTestFile(nameof(EncryptFile_DisableRightsAfterEncrypting));
                        Storage.EncryptFile(path);
                        FileHelper.ReadAllText(path).Should().Be(nameof(EncryptFile_DisableRightsAfterEncrypting));

                        // Add Users group to the DACL
                        using (var handle = Storage.CreateFile(path, CreationDisposition.OpenExisting,
                                                               DesiredAccess.GenericReadWrite | DesiredAccess.WriteDac))
                        {
                            handle.IsInvalid.Should().BeFalse();
                            SID usersGroup = Security.CreateWellKnownSid(WellKnownSID.Users);
                            handle.ChangeAccess(usersGroup, FileAccessRights.GenericRead, AccessMode.Grant);
                        }

                        // Disable the primary user token (prevents using for granting access)
                        using (var restricted = Security.CreateRestrictedToken(token, Security.GetTokenUserSid(token)))
                        {
                            Security.ImpersonateLoggedOnUser(restricted);

                            // The primary user token being disabled doesn't impact the implicit decryption
                            // (We're getting rights to the file through the Users group)
                            FileHelper.ReadAllText(path).Should().Be(nameof(EncryptFile_DisableRightsAfterEncrypting));
                            Security.RevertToSelf();
                        }
                    }
            }));
        }
 public void Setup(Control control, Action <bool, bool> connected, Action <string, string> log)
 {
     this.log       = log;
     this.connected = connected;
     this.uir       = new ControlRunner(control);
     this.ior       = new ThreadRunner("IO", IoException);
 }
Example #13
0
        public void EncryptFile_AccessAsAnonymousAfterEncrypting()
        {
            ThreadRunner.Run((() =>
            {
                using (var cleaner = new TestFileCleaner())
                    using (var token = Security.OpenProcessToken(AccessTokenRights.Duplicate | AccessTokenRights.Query))
                    {
                        // Create and encrypt the file
                        string path = cleaner.CreateTestFile(nameof(EncryptFile_AccessAsAnonymousAfterEncrypting));
                        Storage.EncryptFile(path);
                        FileHelper.ReadAllText(path).Should().Be(nameof(EncryptFile_AccessAsAnonymousAfterEncrypting));

                        // Give anonymous rights
                        using (var handle = Storage.CreateFile(path, CreationDisposition.OpenExisting,
                                                               DesiredAccess.GenericReadWrite | DesiredAccess.WriteDac))
                        {
                            handle.IsInvalid.Should().BeFalse();
                            SID anonymous = Security.CreateWellKnownSid(WellKnownSID.Anonymous);
                            handle.ChangeAccess(anonymous, FileAccessRights.GenericRead, AccessMode.Grant);
                        }

                        // Should still have only one encrypted user
                        var sids = Storage.QueryUsersOnEncryptedFile(path);
                        sids.Count().Should().Be(1);

                        // Try accessing as anonymous
                        Security.ImpersonateAnonymousToken();
                        Action action = () => FileHelper.ReadAllText(path);
                        action.Should().Throw <UnauthorizedAccessException>();
                        Security.RevertToSelf();
                    }
            }));
        }
Example #14
0
    IEnumerator ThreadedAssemble()
    {
        int task = ThreadRunner.CreateThread(new System.Threading.ParameterizedThreadStart(ThreadedSphere), (object)SphereDetail);

        ThreadRunner.StartThread(task);

        while (!ThreadRunner.isComplete(task))
        {
            yield return(null);
        }

        ThreadedSimpleMesh myNewMesh = (ThreadedSimpleMesh)ThreadRunner.FetchData(task);

        Mesh newMesh = myNewMesh.GenerateMesh();
        int  verts   = newMesh.vertexCount;

        if (SaveSphere)
        {
            SaveSphere = false;

            AssetDatabase.CreateAsset(newMesh, "Assets/Meshes/IcoSpheres/IcoSphere-D" + SphereDetail + "-v" + verts + ".asset");
        }

        mf.sharedMesh = newMesh;
    }
Example #15
0
    public IEnumerator GetPathTest(Vector3 entry, Vector3 exit)
    {
        // NavPath = null;
        int   task = ThreadedNavigator.GetPath(entry, exit);
        float time = Time.realtimeSinceStartup;

        while (!ThreadRunner.isComplete(task))
        {
            Debug.Log("Waiting for nav thread to complete...");
            yield return(null);
        }

        List <Vector3> myPath = (List <Vector3>)ThreadRunner.FetchData(task);

        // NavPath = myPath;



        if (myPath == null)
        {
            Debug.Log("No path found.");
        }
        else
        {
            Debug.Log("Path length: " + myPath.Count);

            for (int i = 0; i < myPath.Count - 1; i++)
            {
                Debug.DrawLine(myPath[i], myPath[i + 1], Color.magenta, 5f);
            }
        }
        Debug.Log("Took " + (Time.realtimeSinceStartup - time) + "s to generate.");
    }
Example #16
0
        public void ChangeThreadToImpersonate()
        {
            ThreadRunner.Run((() =>
            {
                using (var token = Security.OpenThreadToken(AccessTokenRights.Query, openAsSelf: true))
                {
                    token.Should().BeNull();
                }

                using (var token = Security.OpenProcessToken(AccessTokenRights.Duplicate | AccessTokenRights.Query))
                {
                    using (var duplicate = Security.DuplicateToken(token, AccessTokenRights.Query | AccessTokenRights.Impersonate, ImpersonationLevel.Impersonation))
                    {
                        using (ThreadHandle thread = Threads.GetCurrentThread())
                        {
                            Security.SetThreadToken(thread, duplicate);

                            // We didn't actually change from what the process token is
                            using (var threadToken = Security.OpenThreadToken(AccessTokenRights.Query, openAsSelf: false))
                            {
                                threadToken.Should().BeNull();
                            }
                        }
                    }
                }
            }));
        }
Example #17
0
        public void DataBinding_BindToBooleanMember()
        {
            ThreadRunner.RunInSTA(delegate {
                //Create the visual
                BoolToVisibilityConverterTestVisual testVisual = new BoolToVisibilityConverterTestVisual();

                //Create the object that the visual will databind to.
                BoolToVisibilityConverterBindableBoolClass dataContext = new BoolToVisibilityConverterBindableBoolClass();
                dataContext.IsVisible1 = true;
                dataContext.IsVisible2 = true;
                testVisual.DataContext = dataContext;

                //Render the visual
                RenderUtility.RenderVisual(testVisual);

                //Check the visibility of the controls
                Assert.IsTrue(testVisual.nonInvertingVisibilityControl.Visibility == Visibility.Visible);
                Assert.IsTrue(testVisual.invertingVisibilityControl.Visibility == Visibility.Collapsed);

                //Negate the visibilities to check that ConvertBack works ok.
                testVisual.NegateCurrentVisbilities();
                RenderUtility.RenderVisual(testVisual);

                //Check the visibility flags in our datacontext
                Assert.IsTrue(dataContext.IsVisible1 == false);
                Assert.IsTrue(dataContext.IsVisible2 == false);
            });
        }
 internal void RegisterExternalRunner(ThreadRunner external)
 {
     lock (_importedThreads)
     {
         _importedThreads.Add(external);
     }
     external.TasksSource = _tasks;
 }
Example #19
0
 public Registration(ThreadRunner sourceRunner, SharedSynchronizationContextImpl targetContext)
 {
     Console.WriteLine($"- Registration on {targetContext.Name}");
     _sourceRunner  = sourceRunner;
     _targetContext = targetContext;
     _nativeQueue   = sourceRunner.TasksSource;
     _targetContext.RegisterExternalRunner(_sourceRunner);
 }
Example #20
0
 public void CurrentObjectInitializationContext_ThreadStatic()
 {
     using (new ObjectInititalizationContextScope(_initializationContext))
     {
         ThreadRunner.Run(() => Assert.That(ObjectInititalizationContextScope.CurrentObjectInitializationContext, Is.Null));
     }
     Assert.That(ObjectInititalizationContextScope.CurrentObjectInitializationContext, Is.Null);
 }
Example #21
0
        public void Run()
        {
            bool threadRun = false;

            ThreadRunner.Run(delegate { threadRun = true; });

            Assert.That(threadRun, Is.True);
        }
Example #22
0
        public void ActiveConfigurationIsThreadSpecific()
        {
            var newConfiguration = new MixinConfiguration();

            MixinConfiguration.SetActiveConfiguration(newConfiguration);

            ThreadRunner.Run(() => Assert.That(MixinConfiguration.ActiveConfiguration, Is.Not.SameAs(newConfiguration)));
        }
Example #23
0
 public void Impersonate_Anonymous()
 {
     ThreadRunner.Run((() =>
     {
         Security.ImpersonateAnonymousToken();
         Security.RevertToSelf();
     }));
 }
 private void TerminalControl_Load(object sender, EventArgs e)
 {
     uir = new ControlRunner(this);
     ior = new ThreadRunner("IO", IoException, IoIdle, 50);
     RefreshSerials();
     EnableControls(true);
     UpdateReadline();
     timer.Enabled = true;
 }
Example #25
0
 public Sensor()
 {
     Class7.RIuqtBYzWxthF();
     this._engine = Engine.Create(Guid.NewGuid().ToString());
     this._engine.Options.CachePath = Guid.NewGuid().ToString();
     this._engine.Start();
     this._threadRunner = new ThreadRunner(Guid.NewGuid().ToString(), this._engine);
     this._webView      = this._threadRunner.CreateWebView();
 }
Example #26
0
        public void Start()
        {
            if (!statisticsRecorder.Enabled || thread != null)
            {
                return;
            }

            thread = ThreadRunner.Run(ThreadRoutine, log);
        }
 internal void RemoveExternalRunner(ThreadRunner external)
 {
     lock (_importedThreads)
     {
         Console.WriteLine($"- RemoveExternalRunner from self: {_name}");
         _importedThreads.Remove(external);
         external.TasksSource = new ConcurrentQueue <LocalTask>();
     }
 }
Example #28
0
		ThreadRunner StartThread (ThreadStart ts)
		{
			ThreadRunner tr = new ThreadRunner();
			tr.SecondaryThread = ts;
			Thread t = new Thread (new ThreadStart (tr.Run));
			tr.RunningThread = t;
			t.Start ();
			return tr;
		}
Example #29
0
        private void RunGesture(IGesture gesture)
        {
            ThreadRunner runner = new ThreadRunner(new ThreadStart(gesture.Start));

            runner.Run();
            if (runner.CatchedException != null)
            {
                Assert.Fail(runner.CatchedException.ToString());
            }
        }
        public ChannelManager(Action <int, string> states = null)
        {
            this.states = states;
            var logfile = Executable.Relative("logs", "ChannelManager.txt");

            this.logger = new Logger(PatternLogFormatter.TIMESTAMP_LEVEL_LINE);
            this.logger.AddAppender(new ConsoleLogAppender());
            this.logger.AddAppender(new WriterLogAppender(logfile));
            this.runner = new ThreadRunner("Manager", OnError, OnIdle, 10);
        }
 void ModbusControl_Load(object sender, EventArgs e)
 {
     uir = new ControlRunner(this);
     ior = new ThreadRunner("IO", (Exception ex) => {
         IoClose();
         uir.Run(() => Log("error", "Error: {0}", ex.Message));
     });
     RefreshSerials();
     EnableControls(true);
     timer.Enabled = pollCheckBox.Checked;
 }
Example #32
0
File: nacl.cs Project: pasko/mono
 static int test_0_threads() {
   // Run a bunch of threads, make them JIT some code and
   // do some casts
   ThreadRunner runner = new ThreadRunner();
   Thread[] threads = new Thread[10];
   for (int i = 0; i < 10; i++) {
     threads[i] = new Thread(new ThreadStart(runner.Run));
     threads[i].Start();
   }
   for (int i = 0; i < 10; i++) {
     threads[i].Join();
   }
   return 0;
 }
Example #33
0
        private int FightThreadCalculation(BackgroundWorker bw, DoWorkEventArgs e)
        {
            if (threadCount > 0)
            {
                //ThreadPool.SetMinThreads(threadCount, threadCount);
                ThreadPool.SetMaxThreads(threadCount, threadCount);
                doneEvents = new ManualResetEvent[threadCount];
                threadRunners = new ThreadRunner[threadCount];
                threadStopFlag = false;

                for (int i = 0; i < threadCount; i++)
                {
                    doneEvents[i] = new ManualResetEvent(true);
                }

                int fightCount = 0;
                int fightReturn = 0;

                //dgvResultGrid.Rows.Clear();
                while (fightReturn < botFights.Count)
                {
                    int doneIndex = WaitHandle.WaitAny(doneEvents);
                    if ((!threadStopFlag) && (!bw.CancellationPending))
                    {
                        //lock (locker)
                        {
                            BotFight bf = null;
                            //int tempFightCount = fightCount;
                            if (threadRunners[doneIndex] != null)
                            {
                                fightReturn++;
                                bf = threadRunners[doneIndex].GetBotFight();
                                int percentComplete =
                                    (int)((float)fightReturn / (float)botFights.Count * 100);
                                backgroundWorker.ReportProgress(percentComplete, bf.FightId());
                            }
                            if (fightCount < botFights.Count)
                            {
                                doneEvents[doneIndex] = new ManualResetEvent(false);
                                threadRunners[doneIndex] = new ThreadRunner(botFights[fightCount], doneEvents[doneIndex]);
                                ThreadPool.QueueUserWorkItem(threadRunners[doneIndex].ThreadPoolCallback, doneIndex);
                                fightCount++;
                                //if (bf != null)
                                //{
                                //    int percentComplete =
                                //        (int) ((float) tempFightCount/(float) botFights.Count*100);
                                //    backgroundWorker.ReportProgress(percentComplete, bf.FightId());
                                //}
                            }
                            else
                            {
                                threadRunners[doneIndex] = null;
                                doneEvents[doneIndex] = new ManualResetEvent(false);
                                //WaitHandle.WaitAll(doneEvents);
                                //break;
                            }

                            /*if (bf != null)
                            {
                                //lock (locker)
                                {
                                    DataGridViewResultOnFly(bf);
                                    this.Text = dgvResultGrid.Rows.Count.ToString() + " of " +
                                                botFights.Count.ToString() + " - " + formTitle;
                                }
                            }*/
                        }
                    }
                    else
                    {
                        e.Cancel = true;
                        break;
                    }
                }

                //for (int i = 0; i < threadRunners.Length; i++)
                //{
                //    int tempFightCount = botFights.Count - threadRunners.Length + i + 1;
                //    BotFight bf = threadRunners[i].GetBotFight();
                //    int percentComplete =
                //        (int)((float)tempFightCount / (float)botFights.Count * 100);
                //    backgroundWorker.ReportProgress(percentComplete, bf.FightId());
                //}
                //WaitHandle.WaitAll(doneEvents);
            }
            //else
            //{
            //    foreach (BotFight botFight in botFights)
            //    {
            //        bool fightResult = FightSimulation.SingleFight(botFight);
            //        botFight.Status(Convert.ToInt32(fightResult));
            //        DataGridViewResultOnFly(botFight);
            //        this.Text = dgvResultGrid.Rows.Count.ToString() + " of " + botFights.Count.ToString() + " - " + formTitle;
            //    }
            //}
            return 1;
        }