jack777 Posted March 12, 2018 Report Share Posted March 12, 2018 Hi, I have a macro that is scheduled to run every minute, it executes a batch script and it takes sometimes more than 1 minute to complete. I don't want the macro to run again if it's already running. How can I achieve that ? Related question : is there a way to wait for a command (the batch script) to terminate before continuing the macro ? Quote Link to comment Share on other sites More sharing options...
rberq Posted March 12, 2018 Report Share Posted March 12, 2018 Didn't you already ask the first question in another thread? I believe the answer was, the scheduled macro will not run again if the previous instance is still running. I would recommend you do some testing to make sure that is true. For your related question, this should work: 1) When your macro starts, create a temp file -- let's call it marker.txt. 2) Start the batch script. 3) Use a Repeat loop to check over and over for the existence of marker.txt. Do not exit from the Repeat loop as long as the file exists. Somewhere inside the Repeat loop, include a few seconds delay -- this is just so looping won't chew up so much processor time. 4) As the last step in your batch script, delete marker.txt. 5) Next time the macro goes through the Repeat loop, the file will no longer exist, so exit from the Repeat and the macro can continue with whatever else it needs to do. Quote Link to comment Share on other sites More sharing options...
jack777 Posted March 12, 2018 Author Report Share Posted March 12, 2018 44 minutes ago, rberq said: Didn't you already ask the first question in another thread? I believe the answer was, the scheduled macro will not run again if the previous instance is still running. I would recommend you do some testing to make sure that is true. For your related question, this should work: 1) When your macro starts, create a temp file -- let's call it marker.txt. 2) Start the batch script. 3) Use a Repeat loop to check over and over for the existence of marker.txt. Do not exit from the Repeat loop as long as the file exists. Somewhere inside the Repeat loop, include a few seconds delay -- this is just so looping won't chew up so much processor time. 4) As the last step in your batch script, delete marker.txt. 5) Next time the macro goes through the Repeat loop, the file will no longer exist, so exit from the Repeat and the macro can continue with whatever else it needs to do. Yes I already asked a similar question... Sorry. But I checked with examples. And I noticed the macro runs again every minute even if the previous instance didn't terminate... I will try your solution... Quote Link to comment Share on other sites More sharing options...
Cory Posted March 12, 2018 Report Share Posted March 12, 2018 As an 'aside'check out the Windows Task Scheduler. You can schedule MEP macros, and other things, from there. Used in combination with MEP's scheduler, one can do some things one can't do with either of them individually. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.