本文整理汇总了C#中Resource.Request方法的典型用法代码示例。如果您正苦于以下问题:C# Resource.Request方法的具体用法?C# Resource.Request怎么用?C# Resource.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resource
的用法示例。
在下文中一共展示了Resource.Request方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Customer
private IEnumerable<Event> Customer(Environment env, string name, Resource counter, TimeSpan meanTimeInBank)
{
var arrive = env.Now;
env.Log("{0} {1}: Here I am", arrive, name);
using (var req = counter.Request()) {
// Wait for the counter or abort at the end of our tether
var timeout = env.TimeoutUniform(MinPatience, MaxPatience);
yield return req | timeout;
var wait = env.Now - arrive;
if (req.IsProcessed) {
// We got the counter
env.Log("{0} {1}: waited {2}", env.Now, name, wait);
yield return env.TimeoutExponential(meanTimeInBank);
env.Log("{0} {1}: Finished", env.Now, name);
} else {
// We reneged
env.Log("{0} {1}: RENEGED after {2}", env.Now, name, wait);
}
}
}
示例2: 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);
}
}
示例3: Machine
static IEnumerable<Event> Machine(Environment env, Resource packer)
{
while (true) {
yield return env.TimeoutNormalPositive(MachineProcTimeMu, MachineProcTimeSigma);
var token = packer.Request();
yield return token;
delay += env.Now - token.Time;
env.Process(Pack(env, packer, token));
}
}
示例4: Cast
private IEnumerable<Event> Cast(Environment env, Resource crane, string name, IEnumerable<Slab> castQueue)
{
foreach (var slab in castQueue) {
yield return env.TimeoutD(slab.CastTime);
env.Log("Caster {0} finished at {1}", name, env.Now);
var token = crane.Request();
yield return token;
env.Process(Transport(env, crane, token, name));
}
}
示例5: Benchmark3Proc
static IEnumerable<Event> Benchmark3Proc(Environment env, Resource resource)
{
while (true) {
var req = resource.Request();
yield return req;
yield return resource.Release(req);
perf++;
}
}
示例6: TestResourceWithUsing
private IEnumerable<Event> TestResourceWithUsing(Environment env, string name, Resource resource,
Dictionary<string, DateTime> log)
{
using (var req = resource.Request()) {
yield return req;
Assert.AreEqual(1, resource.InUse);
yield return env.Timeout(TimeSpan.FromSeconds(1));
}
log.Add(name, env.Now);
}
示例7: TestResourceWithCondition
private IEnumerable<Event> TestResourceWithCondition(Environment env, Resource res)
{
using (var req = res.Request()) {
var timeout = env.Timeout(TimeSpan.FromSeconds(1));
yield return req | timeout;
Assert.IsTrue(req.IsOk);
Assert.IsFalse(timeout.IsProcessed);
}
}
示例8: 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));
}
}
示例9: TestResourceReleaseAfterInterruptVictim
private IEnumerable<Event> TestResourceReleaseAfterInterruptVictim(Environment env, Resource res)
{
var req = res.Request();
yield return req;
Assert.IsFalse(req.IsOk);
Assert.IsTrue(env.ActiveProcess.HandleFault());
// Dont wait for the resource
res.Release(req);
Assert.AreEqual(new DateTime(2014, 4, 1), env.Now);
}
示例10: TestResourceReleaseAfterInterruptBlocker
private IEnumerable<Event> TestResourceReleaseAfterInterruptBlocker(Environment env, Resource res)
{
using (var req = res.Request()) {
yield return req;
yield return env.Timeout(TimeSpan.FromSeconds(1));
}
}
示例11: 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);
}
示例12: 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);
}