Actions in Task Scheduler


  1. Posts : 108
    Windows 10
       #1

    Actions in Task Scheduler


    I have two Scheduled tasks whose actions start the same program, but with different parameters. If these two program instances happen to get scheduled at more or less the same time, then one will wait for the other to finish.

    But it seems to me that sometimes the one which should start second fails to start at all. There is nothing in my code which stops the programs overlapping, apart from their own semaphore mechanism.

    Is there anything in the Task Scheduler itself that would prevent the second task triggering?

    The tasks are triggered by the events "Workstation lock" and "Workstation unlock"; the scheduled task runs a program which turns the display off and on. So, the effect is that the screen always blanks when the desktop locks, and it comes back on when the desktop unlocks.
    Sometimes, the events happen so close to each other than the "display on" and "display off" programs might try to run almost simultaneously, hence my semaphore arrangement,
      My Computer


  2. Posts : 268
    Windows 10 Pro x64 v22H2
       #2

    Never had occasion to review Scheduler Events myself but try event logs to see if they're helpful in seeing what's up.

    Open Task Scheduler. In right pane click Enable All Task History.

    After tasks run, right click the task->Properties and click History tab. (events are listed in reverse time order)


    You can also see all events for all tasks in Event Viewer. Click Applications and Services->Microsoft->Windows->TaskScheduler
      My Computer


  3. Posts : 108
    Windows 10
    Thread Starter
       #3

    OK, I'll give the Event Viewer a go. Because the events include the desktop locking, and the display powering off, it gets a bit tricky trying to see what's going on. Even the event viewer might be difficult... by the time I've got the desktop to unlock and the display to come out of power saving mode, the events of interest may be some way back in the log.
    Time for bed for me now. Back tomorrow.
      My Computer


  4. Posts : 5,478
    2004
       #4

    What do you mean semaphore mechanism? Do you mean some .Net thing that is "not tidy or clearly defined" Source

    Why not try to allocate an object (get an exclusive lock some temporary text file or something) and just wait until you can? Then neither program can interfere with the other.

    I'm not much of a Windows programmer - I would use ALCOBJ if it existed but something like this perhaps?

    windows - How to get an exclusive lock on a file using batch file? - Stack Overflow
      My Computer


  5. Posts : 268
    Windows 10 Pro x64 v22H2
       #5

    yea, logs won't tell you the detail of what's happening within the task but can answer which tasks run in which order and whether answer your question if the 2nd task runs. Might help provide some debug clues
      My Computer


  6. Posts : 108
    Windows 10
    Thread Starter
       #6

    lx07 said:
    Why not try to allocate an object (get an exclusive lock some temporary text file or something) and just wait until you can? Then neither program can interfere with the other.
    That's exactly what I'm doing. The scripting language that I use reads the source code, then closes the file. So the program itself is the file that I use for my semaphore. I just get an exclusive read lock on the program, and I'm away.
    However, some of the scheduled tasks seem not to be running. I get an audible signal that the task should be running, but there's no record in the trace log generated by my program which is the action of the scheduled task.
    The first act of my program is to create a "started" trace entry, and it's these records which are not always appearing.
    If any error occurs in the tracing, the program immediately pauses and waits for me to investigate. This has never happened.

    So, tearing my hear out, I started wondering if there were some locking mechanism in the task scheduler, preventing two tasks colliding when their action is the same program.
    I'm shooting in the dark here...

    For completeness: I have a proximity device that locks and unlocks my desktop depending on where I am. As I approach the PC, I hear the Windows notification sound for the unlock event. This should trigger my "desktop unlocked" scheduled task, but this sometimes doesn't happen. This leaves me with a black screen, which hinders the debugging.
    I'm trying to get the proximity device manufacturer to trace the code around the unlock process, to see if that is failing. But if so, why am I hearing the unlock sound?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:01.
Find Us




Windows 10 Forums