windows task scheduler fails to restart

  • Thread starter Thread starter chandru.govind
  • Start date Start date
C

chandru.govind

Hi,

I built a C# application that scans a folder and pops up a form if
there are any files present in the folder. I have scheduled this as a
task to repeat every 1 min using the windows task scheduler. But what
happens is that if that application is running, the task scheduler
fails to start the same exe. Otherwise it starts it. Do any one have
any suggestions on this problem?

Thanks,
CKG

(P.S: My form app when started, scans for any instance of the same
program running and kills it. It all works fine when i try to run the
exe many times manually!)
 
Try writing it as a service.

Use a timer tick to check the directory and keep track of whether your
form is open or not.
 
Or you could use the filesystem monitoring classes to check if there are
files in the folder.

Lowell
 
Hi,

I built a C# application that scans a folder and pops up a form if
there are any files present in the folder. I have scheduled this as a
task to repeat every 1 min using the windows task scheduler. But what
happens is that if that application is running, the task scheduler
fails to start the same exe. Otherwise it starts it. Do any one have
any suggestions on this problem?

Thanks,
CKG

(P.S: My form app when started, scans for any instance of the same
program running and kills it. It all works fine when i try to run the
exe many times manually!)
How is it possible that the applications runs for more than a minute is the
question you have to answer. If you schedule a task to run every minute, you
have to make sure there is only one instance running.

Willy.
 
When a new instance of the application is opened by manually double
clicking the exe, it kills any previous instances of the same
application and runs this new instance. Its the task scheduler that I
am having problem with! Its not starting this new instance!
Thanks
Chandru
 
Not sure how starting a new instance of an application from the shell can
kill an already running application. Mind to elaborate?

Willy.
 
When a new instance starts it checks if the same process is running
already and kills it. You can easily compare the process ids of the
processes running in the system.
 
Note that none of both, Services and tasks spawned by the scheduler, should
touch the UI, that is, they should not show any window elements like Forms
or Dialogs.

Willy.
 
Ok, I didn't read your original post completely.
One more question, why are you restarting a new instance (that has to kill
the previous instance) every minute?
Why don't you let run your single instance in the first place? You can
prevent a new instance to start from the shell by a guard like a global
mutex.
Note that both Task scheduler and Windows services are not meant to show
anything to the user (no forms or dialogs); they are meant to run when
no-one is even logged-on interactively.

Willy.
 
Back
Top