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


C# Environment.Timeout方法代码示例

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


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

示例1: Car

        private IEnumerable<Event> Car(string name, Environment env, Resource gasStation, Container fuelPump)
        {
            /*
               * A car arrives at the gas station for refueling.
               *
               * It requests one of the gas station's fuel pumps and tries to get the
               * desired amount of gas from it. If the stations reservoir is
               * depleted, the car has to wait for the tank truck to arrive.
               */
              var fuelTankLevel = env.RandUniform(MinFuelTankLevel, MaxFuelTankLevel + 1);
              env.Log("{0} arriving at gas station at {1}", name, env.Now);
              using (var req = gasStation.Request()) {
            var start = env.Now;
            // Request one of the gas pumps
            yield return req;

            // Get the required amount of fuel
            var litersRequired = FuelTankSize - fuelTankLevel;
            yield return fuelPump.Get(litersRequired);

            // The "actual" refueling process takes some time
            yield return env.Timeout(TimeSpan.FromSeconds(litersRequired / RefuelingSpeed));

            env.Log("{0} finished refueling in {1} seconds.", name, (env.Now - start).TotalSeconds);
              }
        }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:26,代码来源:GasStationRefueling.cs

示例2: TestContainerPutter

 private IEnumerable<Event> TestContainerPutter(Environment env, Container buf, List<Tuple<char, DateTime>> log)
 {
     yield return env.Timeout(TimeSpan.FromSeconds(1));
       while (true) {
     yield return buf.Put(2);
     log.Add(Tuple.Create('p', env.Now));
     yield return env.Timeout(TimeSpan.FromSeconds(1));
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:9,代码来源:ContainerTest.cs

示例3: TestDiscreteTimeSteps

 private IEnumerable<Event> TestDiscreteTimeSteps(Environment env, List<DateTime> log)
 {
     while (true) {
     log.Add(env.Now);
     yield return env.Timeout(TimeSpan.FromSeconds(1));
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:7,代码来源:TimeoutTest.cs

示例4: TestRunResume

        public void TestRunResume()
        {
            /* Stopped simulation can be resumed. */
              var env = new Environment();
              var events = new List<Event>() {
            env.Timeout(TimeSpan.FromMinutes(5)),
            env.Timeout(TimeSpan.FromMinutes(10)),
            env.Timeout(TimeSpan.FromMinutes(15)),
            env.Timeout(TimeSpan.FromMinutes(20))
              };

              Assert.AreEqual(env.Now, new DateTime(1970, 1, 1));
              Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 5, 0));
              Assert.IsFalse(events.Any(x => x.IsProcessed));

              env.Run(TimeSpan.FromMinutes(10));
              Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 10, 0));
              Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 10, 0));
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsFalse(events[1].IsProcessed);
              Assert.IsFalse(events[2].IsProcessed);

              env.Run(TimeSpan.FromMinutes(5));
              Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 15, 0));
              Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 15, 0));
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsTrue(events[1].IsProcessed);
              Assert.IsFalse(events[2].IsProcessed);

              env.Run(TimeSpan.FromMinutes(1));
              Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 16, 0));
              Assert.AreEqual(env.Peek(), new DateTime(1970, 1, 1, 0, 20, 0));
              Assert.IsTrue(events[0].IsProcessed);
              Assert.IsTrue(events[1].IsProcessed);
              Assert.IsTrue(events[2].IsProcessed);

              env.Run();
              Assert.AreEqual(env.Now, new DateTime(1970, 1, 1, 0, 20, 0));
              Assert.AreEqual(env.Peek(), DateTime.MaxValue);
        }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:40,代码来源:EnvironmentTests.cs

示例5: TestSharedTimeout

        public void TestSharedTimeout()
        {
            var start = new DateTime(2014, 4, 1);
              var env = new Environment(start);
              var timeout = env.Timeout(TimeSpan.FromSeconds(1));
              var log = new Dictionary<int, DateTime>();
              for (int i = 0; i < 3; i++)
            env.Process(TestSharedTimeout(env, timeout, i, log));
              env.Run();

              Assert.AreEqual(3, log.Count);
              foreach (var l in log.Values)
            Assert.AreEqual(start + TimeSpan.FromSeconds(1), l);
        }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:14,代码来源:TimeoutTest.cs

示例6: TestConditionWithUncaughtError_Process

 private IEnumerable<Event> TestConditionWithUncaughtError_Process(Environment env)
 {
     yield return env.Timeout(TimeSpan.FromDays(1)) | env.Process(TestConditionWithUncaughtError_Explode(env, 2));
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:4,代码来源:ConditionTest.cs

示例7: TestConditionWithUncaughtError_Explode

 private IEnumerable<Event> TestConditionWithUncaughtError_Explode(Environment env, int delay)
 {
     yield return env.Timeout(TimeSpan.FromDays(delay));
       env.ActiveProcess.Fail();
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:5,代码来源:ConditionTest.cs

示例8: FilterStoreConsumerB

 private IEnumerable<Event> FilterStoreConsumerB(Environment env, FilterStore sto)
 {
     while (true) {
     yield return sto.Get(x => x == FilterStoreObjB);
     env.Log("{0}: Consume B", env.Now.Second);
     yield return env.Timeout(TimeSpan.FromSeconds(3));
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:8,代码来源:ResourceTest.cs

示例9: FilterStoreProducer

 private IEnumerable<Event> FilterStoreProducer(Environment env, FilterStore sto)
 {
     while (true) {
     yield return env.Timeout(TimeSpan.FromSeconds(4));
     yield return sto.Put(FilterStoreObjA);
     env.Log("{0}: Produce A", env.Now.Second);
     yield return env.Timeout(TimeSpan.FromSeconds(2));
     yield return sto.Put(FilterStoreObjB);
     env.Log("{0}: Produce B", env.Now.Second);
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:11,代码来源:ResourceTest.cs

示例10: TestMixedPreemtion

 private IEnumerable<Event> TestMixedPreemtion(int id, Environment env, PreemptiveResource res, int delay, int prio, bool preempt, List<Tuple<int, int>> log)
 {
     yield return env.Timeout(TimeSpan.FromSeconds(delay));
       using (var req = res.Request(priority: prio, preempt: preempt)) {
     yield return req;
     yield return env.Timeout(TimeSpan.FromSeconds(5));
     if (!env.ActiveProcess.HandleFault())
       log.Add(Tuple.Create(env.Now.Second, id));
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:10,代码来源:ResourceTest.cs

示例11: TestResourceSlots

   private IEnumerable<Event> TestResourceSlots(Environment env, string name, Resource resource,
 Dictionary<string, DateTime> log)
   {
       using (var req = resource.Request()) {
       yield return req;
       log.Add(name, env.Now);
       yield return env.Timeout(TimeSpan.FromSeconds(1));
         }
   }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:9,代码来源:ResourceTest.cs

示例12: TestResourceImmediateRequests_Child

 private IEnumerable<Event> TestResourceImmediateRequests_Child(Environment env, Resource res)
 {
     var result = new List<int>();
       for (var i = 0; i < 3; i++) {
     using (var req = res.Request()) {
       yield return req;
       result.Add(env.Now.Second);
       yield return env.Timeout(TimeSpan.FromSeconds(1));
     }
       }
       env.ActiveProcess.Succeed(result);
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:12,代码来源:ResourceTest.cs

示例13: TestResourceReleaseAfterInterruptBlocker

 private IEnumerable<Event> TestResourceReleaseAfterInterruptBlocker(Environment env, Resource res)
 {
     using (var req = res.Request()) {
     yield return req;
     yield return env.Timeout(TimeSpan.FromSeconds(1));
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:7,代码来源:ResourceTest.cs

示例14: TestResourceContinueAfterInterruptWaitingVictim

 private IEnumerable<Event> TestResourceContinueAfterInterruptWaitingVictim(Environment env, Resource res)
 {
     var req = res.Request();
       yield return req;
       Assert.IsFalse(req.IsOk);
       env.ActiveProcess.HandleFault();
       yield return env.Timeout(TimeSpan.FromSeconds(2));
       yield return req;
       res.Release(req);
       Assert.AreEqual(new DateTime(2014, 4, 1, 0, 0, 2), env.Now);
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:11,代码来源:ResourceTest.cs

示例15: TestPreemtiveResource

 private IEnumerable<Event> TestPreemtiveResource(int id, Environment env, PreemptiveResource res, int delay, int prio, Dictionary<DateTime, int> log)
 {
     yield return env.Timeout(TimeSpan.FromSeconds(delay));
       using (var req = res.Request(priority: prio, preempt: true)) {
     yield return req;
     yield return env.Timeout(TimeSpan.FromSeconds(5));
     if (!env.ActiveProcess.HandleFault())
       log.Add(env.Now, id);
       }
 }
开发者ID:hsz-develop,项目名称:abeham--SimSharp,代码行数:10,代码来源:ResourceTest.cs


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