none
Running a Desktop App in Batch mode (Task scheduler) without Display RRS feed

  • Question

  • Hello,

    I have a Desktop application that is running fine. It is using Windows Forms for interaction with the user.

    Now there is the request to run this application in the night with Task Scheduler. I made it already possible to start the application with a command line. The application is doing what the command line paramaters says. But the application is still showing what it does. Like showing a progress bar and some other displays. But there are no stops like MessageBox; such messages are all send to a text file (for later review for example).

    I wonder if there is a "easy" way to let my application work with Task scheduler. Right now there is an exception raised when the first ".ShowDialog" comes up.
    Or is there maybe a "Best Practices" for this?


    Viele Grüße / Best regards CSN22


    • Edited by CSN22 Wednesday, April 24, 2019 2:36 PM
    Wednesday, April 24, 2019 2:33 PM

Answers

All replies

  • You probably already have a command line parameter that tells the application that it's running in "automatic" mode, so that the application can shut itself down when it's done. You can also use that parameter to hide the Form when the application starts up, just put this.Hide() in the Form's Paint event handler when that parameter is set. As for the .ShowDialog() issue, you'll obviously have to handle that differently ... but again, use the parameter to determine when do to it differently.


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, April 24, 2019 3:09 PM
    Moderator
  • Thanks Bonnie.

    You are right. I have a parameter that is set when the app is running in "automatic" mode. I am using this paramater already several times. I know I can use it also on ShowDialog(), but I was looking for a more "easy" solution ... Some option or similar that I can set once and everyhting is fine ...


    Viele Grüße / Best regards CSN22



    • Edited by CSN22 Wednesday, April 24, 2019 3:22 PM
    Wednesday, April 24, 2019 3:21 PM
  • I just did a quick Google search. This looks like it might help (although there is more stuff there that you probably don't care about):
    https://www.cyotek.com/blog/creating-long-running-windows-forms-applications-without-a-start-up-form

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by CSN22 Wednesday, April 24, 2019 3:43 PM
    Wednesday, April 24, 2019 3:35 PM
    Moderator
  • Bonnie, thanks again! I wasn't able to find this website with a great example.

    Viele Grüße / Best regards CSN22

    Wednesday, April 24, 2019 3:43 PM
  • I do this for an Excel addin.  I created a bat file.  The bat creates a text file.  I check for the existence of the text file in the addin.  If text file exists it doesn't show form.  After the addin runs the text file is deleted.   Call bat file from Task Scheduler.  You should be able to adapt for C#.

    CD "C:\userdata\selenium\books"
    TYPE NUL > "SearchBN.txt"
    START /B /high /wait /min "" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" "C:\userdata\selenium\books\SearchBN.xlam"
    DEL SearchBN.txt

    Wednesday, April 24, 2019 4:20 PM
  • You're welcome! Glad I could help!  =0)

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, April 25, 2019 4:37 AM
    Moderator