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.
  • B Offline
    B Offline
    baranils
    wrote on last edited by
    #1

    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

    A L P realJSOPR 4 Replies 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

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      CP link [^].

      There's nothing left in my right brain and nothing right in my left brain.

      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

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        B P 3 Replies Last reply
        0
        • L Luc Pattyn

          you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


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

          Thank you Very nice Idea ;) !! Of course I already have my own setting file ! Unfortunately the user wants also to set the time for the given days :(

          1 Reply Last reply
          0
          • L Luc Pattyn

            you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


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

            Thank you Luc Yes I know that link but I do not feel confident with that solution 1- I can't compile it because the post compile event wants to run mt.exe and I don't know why ? 2- As I can see it uses an uggly old fashion dos interface 3- At the first sight I thougt that the goal for that app was to create or edit Windows .job files and let Windows scheduller do the job. If so I do not understand why it needs 7 files of about 100k of source code to do that ? I'm afraid that this is just another scheduller ! But till now it's purpose is not clear to me ?

            L 1 Reply Last reply
            0
            • B baranils

              Thank you Luc Yes I know that link but I do not feel confident with that solution 1- I can't compile it because the post compile event wants to run mt.exe and I don't know why ? 2- As I can see it uses an uggly old fashion dos interface 3- At the first sight I thougt that the goal for that app was to create or edit Windows .job files and let Windows scheduller do the job. If so I do not understand why it needs 7 files of about 100k of source code to do that ? I'm afraid that this is just another scheduller ! But till now it's purpose is not clear to me ?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              I think that wasn't meant for me; maybe it is your reply to Abhinav S? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              B 1 Reply Last reply
              0
              • L Luc Pattyn

                I think that wasn't meant for me; maybe it is your reply to Abhinav S? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


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

                I think that wasn't meant for me; maybe it is your reply to Abhinav S?

                Indeed ! sorry for the mistake

                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

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #8

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

                  B 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    P Online
                    P Online
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    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 1 Reply Last reply
                    0
                    • 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 Online
                        P Online
                        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 Online
                            P Online
                            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 Online
                                    P Online
                                    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 Online
                                        P Online
                                        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
                                          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