Exemplo n.º 1
0
    public IEnumerator TestMultiThreadParallelTaskReset()
    {
        var test = new MultiThreadedParallelTaskCollection("test", 4, false);

        Token token = new Token();

        int done = 0;

        test.onComplete += () => done++;
        test.Add(new WaitEnumerator(token));
        test.Add(new WaitEnumerator(token));
        test.Add(new WaitEnumerator(token));
        test.Add(new WaitEnumerator(token));

        test.Run();

        yield return(new WaitForSeconds(0.5f));

        token.count = 3;

        test.Stop();

        test.Complete();
        test.Dispose();

        Assert.That(done == 1);
        Assert.AreEqual(4, token.count);
    }
        public IEnumerator ParallelMultiThread()
        {
            yield return(null);

            var parallelMultiThread = new MultiThreadedParallelTaskCollection("test", 2, true);

            parallelMultiThread.Add(new SlowTask());
            parallelMultiThread.Add(new SlowTask());

            var sw = System.Diagnostics.Stopwatch.StartNew();

            parallelMultiThread.Complete();
            parallelMultiThread.Dispose();

            sw.Stop();

            Assert.That(sw.ElapsedMilliseconds, Is.AtLeast(900));
            Assert.That(sw.ElapsedMilliseconds, Is.AtMost(1100));
        }