C# 统制 WndProc()接收处理消息的频率
C# 控制 WndProc()接收处理消息的频率
我用终端机扫描信息后 打印扫描的信息 但是由于机器太灵敏 他会出现一秒内扫描很多次 导致会打印出多条 一样的信息
我现在想10秒内 只能处理一次 该怎么弄?。
代码如下:
我用终端机扫描信息后 打印扫描的信息 但是由于机器太灵敏 他会出现一秒内扫描很多次 导致会打印出多条 一样的信息
我现在想10秒内 只能处理一次 该怎么弄?。
代码如下:
DateTime? lastScanTime = null;
protected override void WndProc(ref Message msg)
{
try
{
if (lastScanTime == null)
{
lastScanTime = DateTime.Now;
}
else
{
TimeSpan span = DateTime.Now - lastScanTime.Value;
if (span.Seconds < 10)
return;
}
if (msg.Msg == WM_SCANCODE_ENGINE_NOTIFY) // BarCode的自定义消息通知
{
uint nDataLen = 0; //= (int)msg.WParam;
uint nBarCodeType = 0;// = (uint)msg.LParam;
byte[] BarCodeData;
barcode.GetBarCodeReaderRes(ref nBarCodeType, ref nDataLen, null);
if (nDataLen > 0)
{
string mess = "正在处理";
BarCodeData = new byte[nDataLen];
barcode.GetBarCodeReaderRes(ref nBarCodeType, ref nDataLen, BarCodeData);
string str1 = Encoding.Default.GetString(BarCodeData, 0, (int)nDataLen);
this._BaseForm.DecodeText(ref mess);
this._BaseForm.GetTick(str1, 1);
barcode.DoBeep(1, 50, 80);
}
if (_BaseForm.PrintMessage != "" && _BaseForm.isScan)