本文整理汇总了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);
}
示例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);
}
示例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);
}