Beispiel #1
0
        public void STPAndWIGStartSuspended()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig.WaitForIdle(200));

            wig.Start();

            Assert.IsFalse(wig.WaitForIdle(200));

            stp.Start();

            Assert.IsTrue(wig.WaitForIdle(5000), "WIG is not idle");
            Assert.IsTrue(stp.WaitForIdle(5000), "STP is not idle");
        }
Beispiel #2
0
        public void TwoWIGsStartSuspended()
        {
            SmartThreadPool stp = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig1 = stp.CreateWorkItemsGroup(10, wigStartInfo);
            IWorkItemsGroup wig2 = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig1.QueueWorkItem(new WorkItemCallback(this.DoWork));
            wig2.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig1.WaitForIdle(200));
            Assert.IsFalse(wig2.WaitForIdle(200));

            wig1.Start();

            Assert.IsTrue(wig1.WaitForIdle(200));
            Assert.IsFalse(wig2.WaitForIdle(200));

            wig2.Start();

            Assert.IsTrue(wig1.WaitForIdle(0));
            Assert.IsTrue(wig2.WaitForIdle(200));
        }
Beispiel #3
0
        public int Choice(IEnumerable <Action> actions)
        {
            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                StartSuspended = true
            };
            IWorkItemsGroup  workItemsGroup    = this.CreateWorkItemsGroup(2147483647, wigStartInfo);
            ManualResetEvent anActionCompleted = new ManualResetEvent(false);

            SmartThreadPool.ChoiceIndex choiceIndex = new SmartThreadPool.ChoiceIndex();
            int num = 0;

            foreach (Action current in actions)
            {
                Action act   = current;
                int    value = num;
                workItemsGroup.QueueWorkItem(delegate
                {
                    act();
                    Interlocked.CompareExchange(ref choiceIndex._index, value, -1);
                    anActionCompleted.Set();
                });
                num++;
            }
            workItemsGroup.Start();
            anActionCompleted.WaitOne();
            return(choiceIndex._index);
        }
Beispiel #4
0
 private void Start()
 {
     _workItemsGenerated = 0;
     UpdateControls(true);
     _smartThreadPool.Start();
     _wig1.Start();
     _wig2.Start();
     _wig3.Start();
 }
        internal void Start()
        {
            try
            {
                Writer = new StreamWriter(new FileStream($"{Core.Settings.Directories.LoggerDirectory}/Logger_{DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")}.dat".GetFullPath(), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite), Encoding.UTF8);
            }
            catch (Exception ex)
            {
                ex.CatchError();
            }

            IsActive = true;
            ThreadPool.Start();
        }
Beispiel #6
0
        public void Join(IEnumerable <Action> actions)
        {
            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                StartSuspended = true
            };
            IWorkItemsGroup workItemsGroup = this.CreateWorkItemsGroup(2147483647, wigStartInfo);

            foreach (Action current in actions)
            {
                workItemsGroup.QueueWorkItem(current);
            }
            workItemsGroup.Start();
            workItemsGroup.WaitForIdle();
        }
Beispiel #7
0
        public void Pipe <T>(T pipeState, IEnumerable <Action <T> > actions)
        {
            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                StartSuspended = true
            };
            IWorkItemsGroup workItemsGroup = this.CreateWorkItemsGroup(2147483647, wigStartInfo);

            foreach (Action <T> current in actions)
            {
                Action <T> act = current;
                workItemsGroup.QueueWorkItem(delegate
                {
                    act(pipeState);
                });
            }
            workItemsGroup.Start();
            workItemsGroup.WaitForIdle();
        }
        public void WIGStartSuspended()
        {
            STP stp = new STP();

            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                StartSuspended = true
            };

            IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig.WaitForIdle(200));

            wig.Start();

            Assert.IsTrue(wig.WaitForIdle(200));
        }
Beispiel #9
0
        public void DoWork(object [] states)
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig = smartThreadPool.CreateWorkItemsGroup(1, wigStartInfo);

            foreach (object state in states)
            {
                wig.QueueWorkItem(new
                                  WorkItemCallback(this.DoSomeWork), state);
            }

            // Start working on the work items in the work items group queue
            wig.Start();

            // Wait for the completion of all work items
            wig.WaitForIdle();

            smartThreadPool.Shutdown();
        }