当前位置: 首页>>代码示例>>C#>>正文


C# Func.SerializeMethodHandle方法代码示例

本文整理汇总了C#中Func.SerializeMethodHandle方法的典型用法代码示例。如果您正苦于以下问题:C# Func.SerializeMethodHandle方法的具体用法?C# Func.SerializeMethodHandle怎么用?C# Func.SerializeMethodHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Func的用法示例。


在下文中一共展示了Func.SerializeMethodHandle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoteExecutorServiceExecuteTest

        public void RemoteExecutorServiceExecuteTest()
        {
            // we have generic method handler serializer, so we can use strongly typed functions like this:
            var testMethod = new Func<int, int, int>((a, b) => a + b);

            var service = new RemoteExecutorService();
            var serializedMethodHandle = testMethod.SerializeMethodHandle();
            var eid = service.Initialize(serializedMethodHandle);

            // the following method was private, but it should be public to allow this kind of test
            var executor = RemoteExecutorService.GetExecutor(eid);

            service.Execute(eid, new object[] { 1, 2 }, null);

            // wait for the worker thread to complete
            executor.Join();

            // use method exposed by the service to get computation state
            var result = service.TryJoin(eid);

            result.ExecutorState.ShouldBe(ExecutorState.Finished);
            result.Result.ShouldBe(3);
            result.Error.ShouldBe(null);
            result.ElapsedTime.HasValue.ShouldBe(true);
        }
开发者ID:pbazydlo,项目名称:bluepath,代码行数:25,代码来源:RemoteExecutorServiceTests.cs

示例2: RemoteExecutorServiceGetPerformanceStatisticsTest

        public void RemoteExecutorServiceGetPerformanceStatisticsTest()
        {
            // we have generic method handler serializer, so we can use strongly typed functions like this:
            var testMethod = new Func<int, int, int>(
                (a, b) =>
                    {
                        Thread.Sleep(20);
                        return a + b;
                    });

            var service = new RemoteExecutorService();
            var serializedMethodHandle = testMethod.SerializeMethodHandle();
            var eid = service.Initialize(serializedMethodHandle);
            service.Initialize(serializedMethodHandle);
            service.Initialize(serializedMethodHandle);

            // the following method was private, but it should be public to allow this kind of test
            var executor = RemoteExecutorService.GetExecutor(eid);

            service.Execute(eid, new object[] { 1, 2 }, null);

            var performanceStatistics1 = service.GetPerformanceStatistics();

            if (executor.ExecutorState != ExecutorState.Running)
            {
                Assert.Inconclusive("Executor finished running before getting statistics has finished.");
            }

            // wait for the worker thread to complete
            executor.Join();

            performanceStatistics1.NumberOfTasks[ExecutorState.Running].ShouldBe(1);
            performanceStatistics1.NumberOfTasks[ExecutorState.NotStarted].ShouldBe(2);
            performanceStatistics1.NumberOfTasks[ExecutorState.Finished].ShouldBe(0);
            performanceStatistics1.NumberOfTasks[ExecutorState.Faulted].ShouldBe(0);

            var performanceStatistics2 = service.GetPerformanceStatistics();

            performanceStatistics2.NumberOfTasks[ExecutorState.Running].ShouldBe(0);
            performanceStatistics2.NumberOfTasks[ExecutorState.NotStarted].ShouldBe(2);
            performanceStatistics2.NumberOfTasks[ExecutorState.Finished].ShouldBe(1);
            performanceStatistics2.NumberOfTasks[ExecutorState.Faulted].ShouldBe(0);
        }
开发者ID:pbazydlo,项目名称:bluepath,代码行数:43,代码来源:RemoteExecutorServiceTests.cs

示例3: RemoteExecutorServiceExceptionInUserCodeShouldGetCaughtTest

        public void RemoteExecutorServiceExceptionInUserCodeShouldGetCaughtTest()
        {
            var testMethod = new Func<object>(() => { throw new Exception("test"); });

            var service = new RemoteExecutorService();
            var serializedMethodHandle = testMethod.SerializeMethodHandle();
            var eid = service.Initialize(serializedMethodHandle);
            var executor = RemoteExecutorService.GetExecutor(eid);

            service.Execute(eid, null, null);

            // wait for the worker thread to complete
            executor.Join();

            // use method exposed by the service to get computation state
            var result = service.TryJoin(eid);

            result.ExecutorState.ShouldBe(ExecutorState.Faulted);
            result.Error.Message.Contains("System.Exception: test").ShouldBe(true);
            result.ElapsedTime.HasValue.ShouldBe(true);
        }
开发者ID:pbazydlo,项目名称:bluepath,代码行数:21,代码来源:RemoteExecutorServiceTests.cs


注:本文中的Func.SerializeMethodHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。