クロック操作クラス
4505 ワード
namespace mynamespace
{
public delegate void methodDelegate(object o);
public class TimerHandler
{
private static methodDelegate _method;
private static methodDelegate method
{
get { return _method; }
}
private static Timer _timer = null;
private static Timer timer
{
get
{
if (_timer != null)
{
return _timer;
}
else
{
return new Timer(new TimerCallback(method), null, Timeout.Infinite, Timeout.Infinite);
}
}
}
/// <summary>
///
/// </summary>
public void Start(methodDelegate method)
{
_method = method;
int ScanInterval = 6 * 1000;//ms,6s
if (System.Configuration.ConfigurationSettings.AppSettings["ScanInterval"] != null)
{
ScanInterval = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["ScanInterval"]) * 1000;
}
timer.Change(0, ScanInterval);
}
/// <summary>
///
/// </summary>
public void Stop()
{
timer.Change(Timeout.Infinite, Timeout.Infinite);
}
}
}
次の操作を行います.
TimerHandler t = new TimerHandler();
t.Start(methodName);