0

I am developing an application that will check if certain files have been modified and send an Outlook email notifying the user of said changes. We would like to schedule the task to run every 24 hours. I understand how to do this using Windows task scheduler here: http://windows.microsoft.com/en-in/windows/schedule-task#1TC=windows-7

I have also looked into using a Windows service, but the user would like the ability to specify certain folders to check and modify the email address the report is sent to and I'm not sure how to do that within a service.

I have created a form that would store file paths and the email address within the user-scope of the application. If I schedule a task, however, it will open the form. I would like the form to open only if the user prompts it (by clicking on the .exe.). The application will always run (in the background) every 24 hours based on the most recent settings.

Could I create a form application and have the service call the user settings? I am new to services and I don't know which direction to go in.

I have looked into these:

Best way to run scheduled tasks

how to use windows service in windows form application

WCF using windows service

Some clarification

I need the application to run in the background (checking files + sending email report) every 24 hours without opening any forms.

I need the ability to open the form manually to update settings at any time.

Community
  • 1
  • 1
alybaba726
  • 390
  • 4
  • 14
  • Tony's suggestion to use a command-line parameter seems reasonable and I would not call it a hack. Another possibility is to use the scheduler to run the program under a specified user and the program could somehow check what user it is running as. – Sam Hobbs Apr 12 '16 at 18:31
  • Another possibility might be to write the background part as a Windows Service and then make the UI a separate program. – Sam Hobbs Apr 12 '16 at 18:33
  • @user34660 yes, this is what I was hoping, but I can't find any documentation on it besides the last link I posted. – alybaba726 Apr 12 '16 at 19:49
  • I am sorry, I posted two comments. Are you referring to the one about Windows Services or the one about checking what user it is running as? Unless there is something more than what is in your question, you do not need WCF and there are many articles about writing Windows Services. – Sam Hobbs Apr 12 '16 at 21:21

2 Answers2

0

It looks like you can run it hidden

https://www.calazan.com/windows-tip-run-applications-in-the-background-using-task-scheduler/

enter image description here

In the past, I also used some 3rd party application that can schedule any application to run in the background as a service

Tony
  • 135
  • 9
  • Thanks for this, I know how to schedule a task to run--I just need the form to not open at the scheduled time--only when the user needs to open and save settings (by manually clicking on the executable). – alybaba726 Apr 12 '16 at 17:15
  • Maybe I didn't understand your need correctly. I think you can also hide the form when it starts, only show it when it's needed. You can follow this artcle http://stackoverflow.com/questions/70272/single-form-hide-on-startup – Tony Apr 12 '16 at 18:08
  • I have edited the question again. Hiding the form does not fit my need. I need it to load when the user manually clicks on the .exe, but for it to only run in the background when it is scheduled. As of now, I cannot figure out how to do both within a single application. – alybaba726 Apr 12 '16 at 18:20
  • 1
    one hack is to use command line parameter to determine if it's run as scheduled task. there must be better way but it's not on top of my head. – Tony Apr 12 '16 at 18:23
0
  1. Create a console application
  2. Define a custom configuration section in your app.config https://msdn.microsoft.com/en-us/library/2tw134k3.aspx

  3. The folders to watch can be stored in a different configuration file for ease of maintenance

  4. Implemented FileSystemWatcher for the user selected folders as explained here https://msdn.microsoft.com/en-us/library/2tw134k3.aspx

  5. Map the selected folder watches and create a message queue on the machine that will accumulate all the folder changes

  6. Now write a console application to read the message queue and generate a formatted email for all the affected users

  7. Schedule the console application using the windows task scheduler utility