日期:2014-05-17  浏览次数:20672 次

关于状态监控
项目需要:
1:卡在设备的读取范围内时,设备响应一个动作;
2:卡不在设备的读取范围内时,设备响应另一个动作;
3:如果卡再次回到读取范围内时,设备继续响应第一个动作,
求达人给个思路。谢谢了
C# code





------解决方案--------------------
不就是两个判断吗,你要愿意可以可以搞个timer定时检测或搞个线程后台检测
------解决方案--------------------
C# code
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Monitor monitor = new Monitor();
            monitor.OnReportState += state => { Console.WriteLine(state); };
            monitor.StartMonitor();

            Console.ReadKey();
        }
    }

    public class Monitor
    {
        public delegate void ReportStateHandler(State staet);
        public event ReportStateHandler OnReportState;

        public void StartMonitor()
        {
            State state;
            for (Int32 i = 0; i < 100; i++)
            {
                if (i >= 0 && i < 33)
                {
                    state = State.Low;
                }
                else if (i >= 33 && i < 66)
                {
                    state = State.Medium;
                }
                else
                {
                    state = State.High;
                }

                if (OnReportState != null)
                {
                    OnReportState(state);
                }

                System.Threading.Thread.Sleep(30);
            }
        }
    }

    public enum State 
    { 
        Low, 
        Medium, 
        High 
    }
}