I'm writing a small application that will only run on weekends and weekdays between 6pm and 9am. I intend to do this in the app.config file. I've never worked with the app.config file and I'm looking for some direction on how I would go about implementing this task
Asked
Active
Viewed 272 times
0
-
Believe is better to do it through task scheduler – apomene Jan 25 '17 at 14:47
-
The app config isn't really for this. Why do you wish to use it? – Jan 25 '17 at 14:47
-
`App.config` simply *stores settings*. It doesn't do anything. It's just a file. You'll have to either write the code to schedule and run jobs, or simply add a Scheduled Task. – Panagiotis Kanavos Jan 25 '17 at 14:48
-
I have set up code to send an auto email response. I only want it to run on certain days – Craig Gallagher Jan 25 '17 at 14:48
-
http://www.quartz-scheduler.net/ – Sergey Berezovskiy Jan 25 '17 at 14:49
-
2`I only want it to run on certain days` you'll have to write the code to do this. Why don't you use Scheduled Tasks? The functionality is already there in the operating system – Panagiotis Kanavos Jan 25 '17 at 14:49
-
1@SergeyBerezovskiy that would require either an always running application or a service. Task Scheduler is a safer choice, especially if there is confusion about configuration settings – Panagiotis Kanavos Jan 25 '17 at 14:52
1 Answers
1
Place a time key/value pair in your app.config. Have your code check to determine if the current time is within the time parameters in the app.config.
> > Configuration myConfig = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
> > myConfig.AppSettings.Settings.Add("StartTime", "1800");
> > myConfig.AppSettings.Settings.Add("EndTime", "0900");
> > myConfig.Save(ConfigurationSaveMode.Minimal);
then have your c# code convert the current time to your desired format then check if time is greater than start time and less then end time

jpace7
- 56
- 1
- 3