WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

FAQs - Frequently Asked Questions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Multitasking with Winbatch

Keywords: 	 Multitasking  asynchronous

Question:

My question is whether WinBatch is capable of multitasking, i.e. running different Winbatch programs at the same time. Currently I am not able to do multitasking and asking if there is a way.

Answer:

Depends on what the scripts do. If not more than one of them does SendKeys then you can usually run a bunch of different scripts at the same time.

I have processes where I have to run maybe 2000 scripts. I have a master script that runs about 8 at a time (that pretty much maxes out the cpu). Mostly massive file manipulation stuff.

Basically for multitasking you just run more than one script at a time. You just have to make sure they do not step on each other. I use a "resource lock" (search database for it) to serialize access to files that need it.

In my example, where I'm creating books for an online library, I have source files for the books, and a routine that reads the source file and produces the html pages - breaking the books up into chapters and applying all sorts of html formatting.

One formatting script, when running will do one book but only consumes maybe 15% of the CPU time. So obviously by having multiple jobs running, the whole process can get done faster.

However if too many jobs are running, NT starts thrashing and the jobs never get done. So the trick is to figure out how many jobs just barely max out the cpu and keep that many running.

The manager code looks like:

;Autobookizer
; Keeps eight jobs in the stream
where=AskDirectory("AutoBookize...","d:\","D:\books,"xxx",0)

AddExtender("wsrch34I.dll")
hand=srchInit(where,"*.book","","",0)
count=0
BoxOpen(0,0)
while 1
   wins=WinItemize()
   winlen=strlen(wins)
   bookwin=strreplace(wins,"BOOKIZER","")
   booklen=strlen(bookwin)
   diff=winlen-booklen ; see how much shorted the list of windows is with BOOKIZER's removed
   if diff>=64
       ; eight or more copies running
       ;wait
       TimeDelay(2)
       continue   ; wait 2 seconds try again
   endif


   if diff<64   ; less that 8 copies running.  Start one
       afile=srchNext(hand)
       if afile=="" then break
       axfile=filenameshort(afile)
       wfile=filenameshort("D:\utils\Bookizer.wbt")
       ;Note:  Bookizer.wbt does a BoxTitle("BOOKIZER") as its first instruction
       run("winbatch.exe",strcat(wfile," ",axfile))
       count=count+1
       BoxTitle("AutoBook: %count%")
       BoxText(afile)
       TimeDelay(1)
   endif

endwhile

Message("Autobookizer","Done")

Article ID:   W14114
Filename:   Multitasking with Winbatch.txt
File Created: 2001:03:01:14:46:30
Last Updated: 2001:03:01:14:46:30