📄 sendwindow.cs
字号:
namespace Imps.Client.CommLayer
{
using System;
using System.Collections.Generic;
using System.Threading;
internal sealed class SendWindow
{
private readonly int _maxMessageCount;
private readonly int _period;
private readonly LinkedList<DateTime> _sendTimeList;
public SendWindow(int period, int maxMessageCount)
{
this._period = period;
this._maxMessageCount = maxMessageCount;
this._sendTimeList = new LinkedList<DateTime>();
}
public bool CanSendNow()
{
return this.CanSendNow(false);
}
private bool CanSendNow(bool needWait)
{
DateTime now = DateTime.Now;
lock (this._sendTimeList)
{
this._sendTimeList.AddLast(now);
}
if (this._sendTimeList.get_Count() > this._maxMessageCount)
{
try
{
TimeSpan span;
lock (this._sendTimeList)
{
span = (TimeSpan) (now - this._sendTimeList.get_First().get_Value());
}
if (span.TotalMilliseconds < this._period)
{
if (needWait)
{
Thread.Sleep((int) (this._period - ((int) span.TotalMilliseconds)));
}
return false;
}
}
catch
{
}
finally
{
lock (this._sendTimeList)
{
this._sendTimeList.RemoveFirst();
}
}
}
return true;
}
public void SendRateControl()
{
this.CanSendNow(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -