I have a program that runs an automat, and this automat is connected to various devices that customers might rent for some time. The automat is a Linux machine, so I'm using Mono to make my Visual Studio C# project work on it.
I have created a popup panel that maintenance personell etc. can access to turn devices on and off without having to pay for it. So for this problem I think it should suffice to look at two of the windows forms in the project, frmMain.cs and frmPopupPanel.cs.
frmPopupPanel.cs is started from frmMain.cs by some obscure combination of screen touches, so that regular users won't stumble upon it (I have a PIN code there as well). When I start a device from frmPopupPanel.cs, I need to start a timer that should run for as long as the maintenance person has set it to run.
In frmMain.cs I have a method UpdateDeviceStatus() that is executed every second by another timer to see if the various devices should stay turned on or be turned off. The timers I need to start when I turn on a device should thus be something like this:
int TimeToLive = //this will get the value that the maintenance person specifies
Boolean keedDeviceOn = false;
Timer deviceTimer = new Timer();
deviceTimer.interval = 1000;
deviceTimer.Tick += new Eventhandler(deviceTimer_Tick);
deviceTimer.Enabled = True;
void deviceTimer_Tick(Sender object, Eventargs e)
if (TimeToLive == 0)
keepDeviceOn = false;
keepDeviceOn = true;
Now to the problem. As far as I can see, these timers (one for every device) must be created in frmMain.cs, so that UpdateDeviceStatus can check the boolean value keepDeviceOn for every device when it runs. On the other hand, I need to start the timer from frmPopupPanel.cs when the maintenance person clicks a button there.
I am at loss as to how I should do this. What I've read about timers says that they are started when they are created, so how can I make this work in my program?
I tried setting the parent of frmPopupPanel.cs to frmMain.cs, but it crashed when I tried to run that on the Linux machine, so it appears I cannot use the parent property.