當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。