Model.TimerComponent.WaitAsync C# (CSharp) Method

WaitAsync() public method

public WaitAsync ( long time ) : Task
time long
return Task
		public Task WaitAsync(long time)
		{
			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
			Timer timer = new Timer
			{
				Id = IdGenerater.GenerateId(),
				Time = TimeHelper.Now() + time,
				tcs = tcs
			};
			this.timers[timer.Id] = timer;
			this.timeId.Add(timer.Time, timer.Id);
			return tcs.Task;
		}
	}

Same methods

TimerComponent::WaitAsync ( long time, CancellationToken cancellationToken ) : Task

Usage Example

Esempio n. 1
0
        public async void UpdateAsync()
        {
            TimerComponent timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                // 如果队列中消息多于4个,则加速跑帧
                this.waitTime = maxWaitTime;
                if (this.Queue.Count > 4)
                {
                    this.waitTime = maxWaitTime - (this.Queue.Count - 4) * 2;
                }
                // 最快加速一倍
                if (this.waitTime < 20)
                {
                    this.waitTime = 20;
                }

                await timerComponent.WaitAsync(waitTime);

                if (this.IsDisposed)
                {
                    return;
                }

                this.UpdateFrame();
            }
        }
All Usage Examples Of Model.TimerComponent::WaitAsync