我有这个抽象类:它始终应该有提供抽象方法的逻辑
public abstract class Base
{
protected Timer timer = new Timer { AutoReset = false, Interval = 5000 };
private bool _isTimedOut = false;
public bool IsTimedOut { get { return _isTimedOut; } }
public Base()
{
timer.Elapsed += (o, args) => _isTimedOut = true;
}
public abstract int Recieve(byte[] buffer);
private void TimerReset()
{
timer.Stop();
timer.Start();
}
}
每当收到方法是从一个派生类叫做它应该通过调用TimerReset方法复位定时器时间。我能否提供Recieve方法来重置计时器的逻辑?所以当我在派生类中重写这个成员时,我不必担心重置计时器吗?
你尝试了吗?似乎尝试它(或概念)就像提问并等待回应一样快。顺便说一句,我敢肯定你可以 - 至少我30秒的测试表明你可以。 – Tim 2013-05-09 07:41:42