Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Schedulle a task for some days of the week

Schedulle a task for some days of the week

Scheduled Pinned Locked Moved C#
csharpdesignhelp
21 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PIEBALDconsult

    Luc Pattyn wrote:

    then in your code skip the days that you don't want

    Ew. So how do you test it on those days? Or what if you change your mind?

    B Offline
    B Offline
    baranils
    wrote on last edited by
    #10

    Hello The idea of Luc was very simple (as most of good idea) Let say that I have a settings file giving the needed days (this is the case) When the application start it will check that files and decide to run the process or close So if the Windows scheduller start the application every days the task will only start for the needed days An independent UI (Web Page) can change the setting file at any time The Idea was great but unfortunately not for this case because the User can also choose the starting time

    P 1 Reply Last reply
    0
    • B baranils

      Hello The idea of Luc was very simple (as most of good idea) Let say that I have a settings file giving the needed days (this is the case) When the application start it will check that files and decide to run the process or close So if the Windows scheduller start the application every days the task will only start for the needed days An independent UI (Web Page) can change the setting file at any time The Idea was great but unfortunately not for this case because the User can also choose the starting time

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #11

      I disagree; I don't think the application should be responsible for its own scheduling. And if you later have to develop other similar applications, you would likely wind up with a bunch of duplicate code. Having the scheduling handled outside the application allows it to be shared among any number of applications. And Windows already has a built-in Scheduler that will do what you want; why not use it?

      1 Reply Last reply
      0
      • P PIEBALDconsult

        Use a Windows Scheduled Task to schedule for only those days and times you want it to run.

        B Offline
        B Offline
        baranils
        wrote on last edited by
        #12

        Ok Have a look on the environnement The application should run on a server ONE user uses an interface (web page) on a remote machine to set up the days an time he wants to get some rapport The question is what would be the best way to automaticaly set up the Windows scheduller on the server when the user changes his mind ?

        P 1 Reply Last reply
        0
        • B baranils

          Ok Have a look on the environnement The application should run on a server ONE user uses an interface (web page) on a remote machine to set up the days an time he wants to get some rapport The question is what would be the best way to automaticaly set up the Windows scheduller on the server when the user changes his mind ?

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #13

          Well that's a whole other situation than what you described in the original post. And in that case, I agree with a Windows Service that executes the task when specified. I have written such a scheduler. Tasks were scheduled in a database via whatever client (I used WinForms). I will further state that I stopped using my task scheduler when I made my report scheduler.

          baranils wrote:

          to get some rapport

          I'll assume you mean report. Are the reports generated by Crystal or another report system? If so, I suggest a Service that executes the report more directly, without some other executable in between.

          B 1 Reply Last reply
          0
          • P PIEBALDconsult

            Well that's a whole other situation than what you described in the original post. And in that case, I agree with a Windows Service that executes the task when specified. I have written such a scheduler. Tasks were scheduled in a database via whatever client (I used WinForms). I will further state that I stopped using my task scheduler when I made my report scheduler.

            baranils wrote:

            to get some rapport

            I'll assume you mean report. Are the reports generated by Crystal or another report system? If so, I suggest a Service that executes the report more directly, without some other executable in between.

            B Offline
            B Offline
            baranils
            wrote on last edited by
            #14

            Hello PIEBALDconsult

            Well that's a whole other situation than what you described in the original post.

            Not really :

            My need is to schedulle to run a C# application once a day for some days of the week
            And I provide an UI to set those days

            As I said my C# application do the job (getting date, create report) My application can also read the xml setings file created by the UI I can of course run my application as a service but I see some advantage to keep it as an exe file and try to les Windows schedulle it 1- As long as it only needs to run maximum once a day it is not efficient to let a servis running all the time 2- With an exe we keep the ability to manualy launch som "extra run" if needed

            P 1 Reply Last reply
            0
            • B baranils

              My need is to schedulle to run a C# application once a day for some days of the week And I provide an UI to set those days So I was trying to find out if the best way is to make a service to do that or to programaticaly try to make a new Windows task to run the app as an exe Thanks for your help / suggestion Olivier

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #15

              I wrote some code for that and use it in a windows service: Scheduling Future Dates [^]

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              B 1 Reply Last reply
              0
              • realJSOPR realJSOP

                I wrote some code for that and use it in a windows service: Scheduling Future Dates [^]

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                B Offline
                B Offline
                baranils
                wrote on last edited by
                #16

                Thank you John ! I'll have a look on that

                1 Reply Last reply
                0
                • B baranils

                  Hello PIEBALDconsult

                  Well that's a whole other situation than what you described in the original post.

                  Not really :

                  My need is to schedulle to run a C# application once a day for some days of the week
                  And I provide an UI to set those days

                  As I said my C# application do the job (getting date, create report) My application can also read the xml setings file created by the UI I can of course run my application as a service but I see some advantage to keep it as an exe file and try to les Windows schedulle it 1- As long as it only needs to run maximum once a day it is not efficient to let a servis running all the time 2- With an exe we keep the ability to manualy launch som "extra run" if needed

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #17

                  Don't think so small. If this project is a success they'll ask you to write other such reports that may have to run more than once a day or on demand. It'll be easier in the long run if you provide such flexibility from the start.

                  B 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Don't think so small. If this project is a success they'll ask you to write other such reports that may have to run more than once a day or on demand. It'll be easier in the long run if you provide such flexibility from the start.

                    B Offline
                    B Offline
                    baranils
                    wrote on last edited by
                    #18

                    Yes of course, I agree with you, but practicaly I'll still be happy to understand how to setup the windows scheduller programatically Maybe by simply execute taskschd.exe using System.Diagnostics.Process.Start?

                    P 1 Reply Last reply
                    0
                    • B baranils

                      Yes of course, I agree with you, but practicaly I'll still be happy to understand how to setup the windows scheduller programatically Maybe by simply execute taskschd.exe using System.Diagnostics.Process.Start?

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #19

                      baranils wrote:

                      execute taskschd.exe

                      That's how I've done it in the past. But there oughta be a better way.

                      B 1 Reply Last reply
                      0
                      • P PIEBALDconsult

                        baranils wrote:

                        execute taskschd.exe

                        That's how I've done it in the past. But there oughta be a better way.

                        B Offline
                        B Offline
                        baranils
                        wrote on last edited by
                        #20

                        PIEBALDconsult wrote:

                        That's how I've done it in the past. But there oughta be a better way.

                        Do you know some ?

                        P 1 Reply Last reply
                        0
                        • B baranils

                          PIEBALDconsult wrote:

                          That's how I've done it in the past. But there oughta be a better way.

                          Do you know some ?

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #21

                          No, and I just found this[^].

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups