Can someone explain why running the LargeIntervalTimer works as expected when initializing in a main and using a static delegate, but when using a main which instantiates a class that in turn instantiates a LargeIntervalTimer that calls an intstance delegate ceases to respond after about 3 hours? I am assuming this has something to do with Windows Mobile and its suspend state but would like to hear some concrete reasoning. All code is part of a class called AutoArriveDepart. Any response is much appreciated.
Static Example (Tested for 16 hours):
[MTAThread]
static void Main(String[] args)
{
Cursor.Current = Cursors.Default;
LargeIntervalTimer myTimer = new LargeIntervalTimer();
myTimer.Tick += new EventHandler(myTimer_Tick);
myTimer.Interval = new TimeSpan(0, 1, 0);
myTimer.Enabled = true;
myTimer_Tick(null, null);
while (true)
{
Thread.Sleep(10000);
}
logger.Debug("Exiting Main");
}
static void myTimer_Tick(object sender, EventArgs e)
{
logger.Debug("tick");
SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = @"/windows/notify.wav";
sp.Play();
}
Instance Example (some code removed for brevity. Fails after 3 hours) :
[MTAThread]
static void Main(String[] args)
{
aad = new AutoArriveDepart();
Cursor.Current = Cursors.Default;
while (aad.keepRunning)
{
logger.Debug("Sleeping");
Thread.Sleep(5000);
logger.Debug("Awake");
Application.DoEvents();
logger.Debug("Finished DoEvents()");
}
aad.CloseSystemTrayIcon();
logger.Debug("Exiting Main");
}
public AutoArriveDepart()
{
collectionTimer = new LargeIntervalTimer();
collectionTimer.Interval = new TimeSpan(0, 1, 0);
collectionTimer.Tick +=new EventHandler(collectionTimer_Tick);
collectionTimer.Enabled = true;
}
void collectionTimer_Tick(object sender, EventArgs e)
{
logger.Debug("tick");
SoundPlayer sp = new SoundPlayer();
sp.SoundLocation = @"/windows/notify.wav";
sp.Play();
}