コード例 #1
0
 /// <summary>使用信号号方式限制异步方法并发量</summary>
 /// <param name="source">一个值序列,要对该序列调用转换函数。</param>
 /// <param name="selector">应用于每个元素的转换函数。</param>
 /// <param name="token">The token.</param>
 /// <param name="maxParallel">最大并行执行量,≤1时为CPU核心数量</param>
 /// <remarks>不要对已经开始的Task进行限制,比如List&lt;Task&gt;,因为Task已经开始了。</remarks>
 public static IEnumerable <Task> ParallelSelect <TSource>(this IEnumerable <TSource> source, Func <TSource, Task> selector, CancellationToken token, int maxParallel = 0)
 {
     using (var enumerator = source.GetEnumerator())
     {
         var invoker = new ParallelInvoker(maxParallel, token);
         while (enumerator.MoveNext())
         {
             yield return(invoker.Invoke(enumerator.Current, selector));
         }
     }
 }
コード例 #2
0
        public void ShouldUseExecutonEngine()
        {
            _workflow.Do(a => a += ", yellow").And.Do(b => b += ", orange").Then();
            var func1 = ((ParallelInvoker<string>)_workflow.RegisteredOperations.Tasks[0].Command).RegisteredOperations[0];
            var func2 = ((ParallelInvoker<string>)_workflow.RegisteredOperations.Tasks[0].Command).RegisteredOperations[1];

            var ps = new ParallelInvoker<string>(_engine);

            ps.RegisteredOperations.Add(func1);
            ps.RegisteredOperations.Add(func2);

            Expect.Call(_engine.Execute(func1, "Red")).Return("Red, yellow").IgnoreArguments().Repeat.Twice();
            _mocker.ReplayAll();

            var result = ps.Execute("Red");
            _mocker.VerifyAll();
        }
コード例 #3
0
        public void ShouldUseExecutonEngine()
        {
            _workflow.Do(a => a += ", yellow").And.Do(b => b += ", orange").Then();
            var func1 = ((ParallelInvoker <string>)_workflow.RegisteredOperations.Tasks[0].Command).RegisteredOperations[0];
            var func2 = ((ParallelInvoker <string>)_workflow.RegisteredOperations.Tasks[0].Command).RegisteredOperations[1];

            var ps = new ParallelInvoker <string>(_engine);

            ps.RegisteredOperations.Add(func1);
            ps.RegisteredOperations.Add(func2);

            Expect.Call(_engine.Execute(func1, "Red")).Return("Red, yellow").IgnoreArguments().Repeat.Twice();
            _mocker.ReplayAll();

            var result = ps.Execute("Red");

            _mocker.VerifyAll();
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: mbahar94/fracture
        public Game () {
            Graphics = new GraphicsDeviceManager(this);
            Graphics.PreferredBackBufferWidth = Width;
            Graphics.PreferredBackBufferHeight = Height;
            Graphics.PreferMultiSampling = false;
            Graphics.SynchronizeWithVerticalRetrace = true;

            UseThreadedDraw = ThreadedPaint;
            IsFixedTimeStep = false;
            Content.RootDirectory = "Content";

#if XBOX
            Components.Add(new KiloWatt.Runtime.Support.ThreadPoolComponent(this));
#endif

            ParallelUpdater = new ParallelInvoker<UpdateArgs>(
                this, ParallelUpdateOrbs, ThreadedUpdate
            );
            ParallelDrawer = new ParallelInvoker<DrawArgs>(
                this, ParallelPrepareOrbs, ThreadedPaint
            );
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: sq/Fracture
        public Game()
        {
            Graphics = new GraphicsDeviceManager(this);
            Graphics.PreferredDepthStencilFormat = DepthFormat.None;
            Graphics.PreferredBackBufferWidth = Width;
            Graphics.PreferredBackBufferHeight = Height;
            Graphics.PreferMultiSampling = false;
            Graphics.SynchronizeWithVerticalRetrace = true;

            UseThreadedDraw = ThreadedPaint;
            IsFixedTimeStep = false;
            Content.RootDirectory = "Content";

            ParallelUpdater = new ParallelInvoker<UpdateArgs>(
                this, ParallelUpdateOrbs, ThreadedUpdate
            );
            ParallelDrawer = new ParallelInvoker<DrawArgs>(
                this, ParallelPrepareOrbs, ThreadedPaint
            );
        }