本文整理汇总了C#中System.Environment.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Environment.Run方法的具体用法?C# Environment.Run怎么用?C# Environment.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Environment
的用法示例。
在下文中一共展示了Environment.Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestTriggeredTimeout
public void TestTriggeredTimeout()
{
var env = new Environment();
env.Process(TestTriggeredTimeout(env));
env.Run();
Assert.AreEqual(2, env.NowD);
}
示例2: TestErrorAndInterruptedJoin
public void TestErrorAndInterruptedJoin()
{
var executed = false;
var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0));
env.Process(ErrorAndInterruptedJoinParent(env, () => executed = true));
env.Run();
Assert.IsTrue(executed);
}
示例3: TestGetState
public void TestGetState()
{
// A process is alive until it's generator has not terminated.
var env = new Environment();
var procA = env.Process(GetStatePemA(env));
env.Process(GetStatePemB(env, procA));
env.Run();
}
示例4: TestExit
public void TestExit()
{
// Processes can set a return value
var executed = false;
var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0));
env.Process(ExitParent(env, () => executed = true));
env.Run();
Assert.IsTrue(executed);
}
示例5: Simulate
public void Simulate()
{
var env = new Environment(randomSeed: 41);
var packer = new Resource(env, 1);
env.Process(Machine(env, packer));
env.Process(Machine(env, packer));
env.Run(TimeSpan.FromHours(8));
Console.WriteLine("The machines were delayed for {0}", delay);
}
示例6: Simulate
public void Simulate()
{
var env = new Environment(TimeSpan.FromMinutes(1));
env.Log("== Steel Factory ==");
var crane = new Resource(env, 1);
env.Process(Cast(env, crane, "CC1", new[] { new Slab(4), new Slab(4), new Slab(8), new Slab(3), new Slab(2) }));
env.Process(Cast(env, crane, "CC2", new[] { new Slab(2), new Slab(3), new Slab(3), new Slab(4), new Slab(3) }));
env.Run(TimeSpan.FromMinutes(100));
}
示例7: Benchmark2
/// <summary>
/// This method will benchmark Sim#'s performance with respect to creation
/// of entities. In SimPy and also Sim# the equivalence of an entity is a
/// process. This stress tests the performance of creating processes.
/// </summary>
static long Benchmark2(Environment env)
{
perf = 0;
env.Process(Benchmark2Source(env));
var watch = Stopwatch.StartNew();
env.Run(terminate);
watch.Stop();
return watch.ElapsedTicks;
}
示例8: TestChildException
public void TestChildException()
{
// A child catches an exception and sends it to its parent.
// This is the same as TestExit
var executed = false;
var env = new Environment(new DateTime(1970, 1, 1, 0, 0, 0));
env.Process(ChildExceptionParent(env, () => executed = true));
env.Run();
Assert.IsTrue(executed);
}
示例9: TestEventQueueEmpty
public void TestEventQueueEmpty()
{
/*The simulation should stop if there are no more events, that means, no
more active process.*/
var log = new List<string>();
var env = new Environment();
env.Process(AProcess(env, log));
env.Run(TimeSpan.FromMinutes(10));
Assert.IsTrue(log.SequenceEqual(new[] { "00", "01" }));
}
示例10: TestAnyOfEmptyList
public void TestAnyOfEmptyList()
{
var env = new Environment();
var evt = new AnyOf(env, Enumerable.Empty<Event>());
Assert.IsTrue(evt.IsTriggered);
Assert.IsFalse(evt.IsProcessed);
env.Run(evt);
Assert.IsTrue(evt.IsProcessed);
Assert.AreEqual(0, env.NowD);
}
示例11: Invoke
public object Invoke(Environment e, object[] args)
{
foreach (object o in argnames)
{
// FIXME
e.Set(o.ToString(), e.GetObject(o.ToString()));
}
return e.Run(Pieces.ToArray());
// TODO: remove args from env
}
示例12: TestFilterCallsBestCase
public void TestFilterCallsBestCase()
{
var env = new Environment();
var store = new FilterStore(env, new object[] { 1, 2, 3 }, 3);
var log = new List<string>();
Func<object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return true; };
env.Process(TestFilterCallsBestCaseProcess(store, filterLogger, log));
env.Run();
Assert.IsTrue(log.SequenceEqual(new[] { "check 1", "get 1", "check 2", "get 2", "check 3", "get 3" }));
}
示例13: Benchmark1
/// <summary>
/// This method will benchmark Sim#'s performance with respect to the list
/// of future events. A large number of processes that exist in the system
/// stress tests the performance of operations on the event queue.
/// </summary>
/// <param name="n">The number of concurrent processes.</param>
static long Benchmark1(Environment env, int n)
{
perf = 0;
for (var i = 0; i < n; i++) {
env.Process(Benchmark1Proc(env, n));
}
var watch = Stopwatch.StartNew();
env.Run(terminate);
watch.Stop();
return watch.ElapsedTicks;
}
示例14: Benchmark3
/// <summary>
/// This method will benchmark Sim#'s performance with respect to
/// seizing and releasing resources, a common task in DES models.
/// </summary>
static long Benchmark3(Environment env)
{
perf = 0;
var res = new Resource(env, capacity: 1);
env.Process(Benchmark3Proc(env, res));
env.Process(Benchmark3Proc(env, res));
var watch = Stopwatch.StartNew();
env.Run(terminate);
watch.Stop();
return watch.ElapsedTicks;
}
示例15: Simulate
private static readonly TimeSpan MinPatience = TimeSpan.FromMinutes(1); // Min. customer patience
#endregion Fields
#region Methods
public void Simulate(int rseed = 41)
{
// Setup and start the simulation
var start = new DateTime(2014, 2, 1);
// Create an environment and start the setup process
var env = new Environment(start, 41);
env.Log("== Bank renege ==");
var counter = new Resource(env, capacity: 1);
env.Process(Source(env, counter));
env.Run();
}