|
|
|
@ -15,6 +15,8 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Security.Policy;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using Tool;
|
|
|
|
@ -55,6 +57,7 @@ namespace RfidWeb
|
|
|
|
|
private void Init()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ShowLed();
|
|
|
|
|
_timer = new TimerX(TimeState, null, 2000, 1000);
|
|
|
|
|
_timer.Async=true;
|
|
|
|
|
// 如果所有的日志在记录之前需要在控制台显示出来
|
|
|
|
@ -81,6 +84,9 @@ namespace RfidWeb
|
|
|
|
|
/// <summary>移除过期的缓存项</summary>
|
|
|
|
|
void TimeState(Object state)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isExit = UserManager.IsExit();
|
|
|
|
|
this.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
@ -110,7 +116,8 @@ namespace RfidWeb
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ThreadPoolX.QueueUserWorkItem(ShowLed);
|
|
|
|
|
if (!PlcConnect.IsSuccess) return;
|
|
|
|
|
|
|
|
|
|
ThreadPoolX.QueueUserWorkItem(UpdateLog);
|
|
|
|
|
ThreadPoolX.QueueUserWorkItem(ReadBufLog);
|
|
|
|
|
|
|
|
|
@ -121,12 +128,28 @@ namespace RfidWeb
|
|
|
|
|
|
|
|
|
|
private void ShowLed()
|
|
|
|
|
{
|
|
|
|
|
CacheManager.Act(CacheKeyManager.Home, () =>
|
|
|
|
|
|
|
|
|
|
var _cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
var token = _cancellationTokenSource.Token;
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
while (!token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
// 在这里执行你的轮询逻辑
|
|
|
|
|
var result =await PlcConnect.Instance.ReadPlcTypeAsync();
|
|
|
|
|
hslLanternSimplePlc.LanternBackground = result.IsSuccess
|
|
|
|
|
? Color.LimeGreen : Color.Red;
|
|
|
|
|
// 在主线程更新 UI
|
|
|
|
|
//Invoke(new Action(() =>
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
//}));
|
|
|
|
|
PlcConnect.IsSuccess = result.IsSuccess;
|
|
|
|
|
await Task.Delay(1000, token); // 每隔一秒延时
|
|
|
|
|
}
|
|
|
|
|
}, token);
|
|
|
|
|
|
|
|
|
|
bool result = PlcConnect.IsSuccess;
|
|
|
|
|
hslLanternSimplePlc.LanternBackground = result ? Color.LimeGreen : Color.Red;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReadBufLog()
|
|
|
|
|