本文整理汇总了C#中System.Diagnostics.Stopwatch.ElapsedSeconds方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.ElapsedSeconds方法的具体用法?C# Stopwatch.ElapsedSeconds怎么用?C# Stopwatch.ElapsedSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.ElapsedSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RPCServerUpdate
/// <summary>
/// Update the RPC server, called once every FixedUpdate.
/// This method receives and executes RPCs, for up to MaxTimePerUpdate microseconds.
/// RPCs are delayed to the next update if this time expires. If AdaptiveRateControl
/// is true, MaxTimePerUpdate will be automatically adjusted to achieve a target framerate.
/// If NonBlockingUpdate is false, this call will block waiting for new RPCs for up to
/// MaxPollTimePerUpdate microseconds. If NonBlockingUpdate is true, a single non-blocking call
/// will be made to check for new RPCs.
/// </summary>
void RPCServerUpdate()
{
var timer = Stopwatch.StartNew ();
var pollTimeout = new Stopwatch ();
var pollTimer = new Stopwatch ();
var execTimer = new Stopwatch ();
long maxTimePerUpdateTicks = StopwatchExtensions.MicrosecondsToTicks (MaxTimePerUpdate);
long recvTimeoutTicks = StopwatchExtensions.MicrosecondsToTicks (RecvTimeout);
ulong rpcsExecuted = 0;
var yieldedContinuations = new List<RequestContinuation> ();
rpcServer.Update ();
while (true) {
// Poll for RPCs
pollTimer.Start ();
pollTimeout.Reset ();
pollTimeout.Start ();
while (true) {
PollRequests (yieldedContinuations);
if (!BlockingRecv)
break;
if (pollTimeout.ElapsedTicks > recvTimeoutTicks)
break;
if (timer.ElapsedTicks > maxTimePerUpdateTicks)
break;
if (continuations.Any ())
break;
}
pollTimer.Stop ();
if (!continuations.Any ())
break;
// Execute RPCs
execTimer.Start ();
foreach (var continuation in continuations) {
// Ignore the continuation if the client has disconnected
if (!continuation.Client.Connected)
continue;
// Max exec time exceeded, delay to next update
if (timer.ElapsedTicks > maxTimePerUpdateTicks) {
yieldedContinuations.Add (continuation);
continue;
}
// Execute the continuation
try {
ExecuteContinuation (continuation);
} catch (YieldException e) {
yieldedContinuations.Add ((RequestContinuation)e.Continuation);
}
rpcsExecuted++;
}
continuations.Clear ();
execTimer.Stop ();
// Exit if only execute one RPC per update
if (OneRPCPerUpdate)
break;
// Exit if max exec time exceeded
if (timer.ElapsedTicks > maxTimePerUpdateTicks)
break;
}
// Run yielded continuations on the next update
continuations = yieldedContinuations;
timer.Stop ();
RPCsExecuted += rpcsExecuted;
TimePerRPCUpdate = (float)timer.ElapsedSeconds ();
PollTimePerRPCUpdate = (float)pollTimer.ElapsedSeconds ();
ExecTimePerRPCUpdate = (float)execTimer.ElapsedSeconds ();
}