Is creating thread good idea to check variable

I made an application in which i am writing an INI file.i want to continuously monitor an variable.
To do so should i create thread and do something like this;-
1
2
3
4
5
6
void CTIMSStreamerDlg::CheckVariableThread()
{
int check= iniReader.ReadInteger("Setting", "status", "1");
if(check==1)
//Do what u want
}


Is creating thread good idea or is any other idea better than creating thread?
I'm not 100% sure but it seems like overkill to create a new thread just to monitor a variable. Under what conditions can that variable change and why does it need to be monitored constantly ? If it's part of INI settings u can keep it on the free store. A user will typically not interact directly with an INI file and any changes directly made should be loaded only when the program is restarted...
Actually i am developing a service and a gui in c# the service and gui will interact through INI,there is an option in GUI to give time restart service at a particular time.
Now in my service i have to continuously check the time written in INI with current system time and restart the service if time matches
If the GUI and service are running on the same computer, why not use an event to signal the change? You should try to avoid polling when possible.
ya sir you are correct we should avoid polling but the reason for this polling is it may be the case that GUI might not be running or the end user have shut down the GUI after doing all the setting.
it may be the case that GUI might not be running or the end user have shut down the GUI after doing all the setting.

Are you saying that the user will sometimes modify the INI without the gui ?

The gui is the user's communication with the service. When the gui is off the service should have all of those settings updated for itself and not ever check that one of those settings changed until the gui is back online (and more specifically, like kbw said, it is not until the gui detects a change in the settings from the user should it notify the service).
Last edited on
Topic archived. No new replies allowed.