﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>MULTITHREADING</title><link>http://www.visualbasicscript.com/</link><description /><copyright>(c) VBScript Forum</copyright><ttl>30</ttl><item><title> RE: Re: MULTITHREADING (sivaonview)</title><description>  Hi CaffeineAddiction, &lt;br&gt;   &lt;br&gt;  Iam facing the same probelm as pinging takes hours of my time.. &lt;br&gt;  i tried to see the link  &amp;lt;&amp;lt;&amp;lt; &lt;a href="http://visualbasicscript.com/topic.asp?TOPIC_ID=2403" target="_blank" rel="nofollow"&gt;http://visualbasicscript.com/topic.asp?TOPIC_ID=2403&lt;/a&gt; &amp;gt;&amp;gt;&amp;gt; its not found there.. &lt;br&gt;  &amp;nbsp;can u repost the script..plz. &lt;br&gt;   &lt;br&gt;  Thnx. &lt;br&gt;   &lt;br&gt;   </description><link>http://www.visualbasicscript.com/fb.ashx?m=51970</link><pubDate>Wed, 19 Sep 2007 00:09:58 GMT</pubDate></item><item><title>Re: MULTITHREADING (drbelden)</title><description> Ooops. Didn't see page 2. </description><link>http://www.visualbasicscript.com/fb.ashx?m=18312</link><pubDate>Tue, 19 Apr 2005 14:44:09 GMT</pubDate></item><item><title>Re: MULTITHREADING (drbelden)</title><description> On the topic of realtime status, have you though about automating IE to display your output. I haven't used it before, but I know I've seen something on it in one of my Enterprise scripting reference books. </description><link>http://www.visualbasicscript.com/fb.ashx?m=18311</link><pubDate>Tue, 19 Apr 2005 14:39:58 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> Thanks, I'll check it out =) &lt;br&gt;  &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18310</link><pubDate>Sun, 20 Mar 2005 23:45:13 GMT</pubDate></item><item><title>Re: MULTITHREADING (CaffeineAddiction)</title><description> Ok, I decided to Put my script in a new thread ... you can find it here &lt;br&gt;  &lt;br&gt; &amp;lt;&amp;lt;&amp;lt; &lt;a href="http://visualbasicscript.com/topic.asp?TOPIC_ID=2403" target="_blank" rel="nofollow"&gt;http://visualbasicscript.com/topic.asp?TOPIC_ID=2403&lt;/a&gt; &amp;gt;&amp;gt;&amp;gt; </description><link>http://www.visualbasicscript.com/fb.ashx?m=18309</link><pubDate>Sun, 20 Mar 2005 22:21:44 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> heh..sure.. no problem =) </description><link>http://www.visualbasicscript.com/fb.ashx?m=18308</link><pubDate>Sat, 19 Mar 2005 16:05:15 GMT</pubDate></item><item><title>Re: MULTITHREADING (CaffeineAddiction)</title><description> Darn it .. they decided to do some repair work on the DC over Sat, so I will have to post the scripts on Sun ... i knew i should have kept those scripts localy instead of on the file server oh well. </description><link>http://www.visualbasicscript.com/fb.ashx?m=18307</link><pubDate>Sat, 19 Mar 2005 15:39:23 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> What exactly did you do with the scripts ? Just pulling data from WMI queries and store them in some place or are you doing something immediately upon receiving the returned queries for the individual computers ? &lt;br&gt;  &lt;br&gt; Yeah, could you post the scripts please =) &lt;br&gt;  &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18306</link><pubDate>Sat, 19 Mar 2005 15:01:16 GMT</pubDate></item><item><title>Re: MULTITHREADING (CaffeineAddiction)</title><description> That is similar to a script that i wrote just recently ... i will have to go into work tommorow to snag it and post it up, but basicly I have 2000+ workstations that I need to poll for data (usualy through wmi queries) and waiting on a responce from one computer before asking another computer is painful and can take upwards of 6+ hrs to run.  What I did, was take a .txt file full of computernames and have a script i dubbed the "batch.vbs" to read this textfile and start up the second script "*.vbs" (named according to what its searching for) with an arguement of the computername &lt;br&gt;  &lt;br&gt; this is allows me to poll upwards of 30 comptuers a second (limited only by a .sleep command) that keeps me from crashing the machine im running the script from &lt;br&gt;  &lt;br&gt; Edit: forgot to mention that this takes the 6+ hrs of runtime and crams it into 30 min + or - a few with less than 3% network utilization (meaning i can run it durring the day with out slowing the network to a grinding hault) &lt;br&gt;  &lt;br&gt; I dont know if this is exactly what you are looking for, but If it is ... i will post my source by noon tommorow </description><link>http://www.visualbasicscript.com/fb.ashx?m=18305</link><pubDate>Fri, 18 Mar 2005 23:39:45 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> Interesting example =) &lt;br&gt;  &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18304</link><pubDate>Fri, 18 Mar 2005 23:28:54 GMT</pubDate></item><item><title>Re: MULTITHREADING (toddio)</title><description> token: &amp;gt; this thread hurts my head &lt;br&gt;  &lt;br&gt; I'd say that a "thread" about "multi-threading" branching into multiple sub-threads sounds somehow appropriate. It's good conceptual practice. =) &lt;br&gt;  &lt;br&gt;  &lt;br&gt; So anyway, I came up with a contrived example of multi threading, which is basically a main script running several sub scripts. The main script then watches a text file to wait until all of the sub scripts have finished. &lt;br&gt;  &lt;br&gt; I then went and looked at that ThreadForker routine and it seems to be a similar kind of thing, but with the capability of killing sub processes that run for too long. &lt;br&gt;  &lt;br&gt; However, my example is smaller and simpler and demonstrates multiple scripts reading and writing the same text file, so I'm posting it for everyone's amusement. &lt;br&gt;  &lt;br&gt; &lt;pre class="prettyprint"&gt;
'- MainScript.vbs
'  Todd Fiske
'  2005-03-19 00:11:19

'- start several instances of SubScript each in their own minimized window

'- each subscript will be passed a random number which basically means how
'  many times to execute its main loop

'  the loop will just sleep for a random amount of time then write a line to
'  an output text file

'  when done looping, the subscript will write a "done" line to a tracking
'  text file

'- after starting the instances of SubScript, MainScript will run a loop that
'  reads the tracking text file and continues until all of the subscripts
'  report that they are done

Option Explicit
Randomize

dim fso, shl
set fso = CreateObject("Scripting.FileSystemObject")
set shl = CreateObject("WScript.Shell")

dim nSubScripts, nScript, nArg
dim aSubScripts()
dim sCmd, nRet, bDone, bRunning
dim f, sFile, aFile, sLine, nNum, bFlag, nLoop
dim sTrackingFile, sOutputFile

sTrackingFile = "MultiScripts.txt"
sOutputFile   = "MultiOutput.txt"

'- choose number of subscripts to run
nSubScripts = ( Rnd * 10 ) + 5 '- run between 5 and 14 sub scripts
say "creating " &amp; nSubScripts &amp; " sub scripts"
redim aSubScripts(nSubScripts)

'- delete tracking and output files
on error resume next
fso.DeleteFile(sTrackingFile)
fso.DeleteFile(sOutputFile)
on error goto 0

'- launch subscripts
nScript = 1
do while nScript &amp;lt;= nSubScripts
nArg = (rnd * 20 ) + 10 '- 10 to 29

sCmd = "cscript SubScript.vbs " &amp; nScript &amp; " " &amp; nArg
nRet = shl.Run(sCmd, 2, false) '- run minimized, don't wait
aSubScripts(nScript) = true '- set Running flag

say sCmd &amp; " -&amp;gt; " &amp; nRet

nScript = nScript + 1
loop


'- loop until all subscripts are done
bDone = false
nLoop = 1
say "looping until all sub-scripts are done"
do until bDone
WScript.Sleep 100

'- load file into string
if fso.FileExists(sTrackingFile) then
set f = fso.OpenTextFile(sTrackingFile, 1) '- for reading
sFile = f.ReadAll
f.Close

'- split into array
sFile = Left(sFile, len(sFile) - 2) '- trim final CRLF
aFile = Split(sFile, vbCrLf)

'- turn off any flags for sub scripts that have finished
for each sLine in aFile
nNum = Trim(Mid(sLine,11,2)) '- extract number "SubScript ## done"
if aSubScripts(nNum) then
say sLine
aSubScripts(nNum) = false '- set that item of aSubScripts to false
end if
next

'- see if anyone is still running
bRunning = false
for each bFlag in aSubScripts
bRunning = bRunning or bFlag
next

bDone = not bRunning
end if

nLoop = nLoop + 1
loop

say "done after " &amp; nLoop &amp; " loops"

'---

sub Say(s)
WScript.Echo s
end sub

'===&lt;/pre&gt; &lt;br&gt;  &lt;br&gt; &lt;pre class="prettyprint"&gt;
'- SubScript.vbs

Option Explicit
Randomize

dim nID, nArg, nLoop, nSleep, sLine
dim fso, f
set fso = CreateObject("Scripting.FileSystemObject")

nID  = WScript.Arguments(0)
nArg = Int(WScript.Arguments(1))

'~ could get filenames as parameters too

WScript.Echo "running SubScript " &amp; nID &amp; " " &amp; nArg
WScript.Echo "looping " &amp; nArg &amp; " times"

nLoop = 0
do while nLoop &amp;lt; nArg
nSleep = (rnd * 5) + 3 '- 3 to 7
WScript.Sleep nSleep * 1000

sLine = "SubScript " &amp; nID &amp; " slept for " &amp; nSleep &amp; " seconds on loop " &amp; nLoop &amp; " of " &amp; nArg
WScript.Echo sLine

set f = fso.OpenTextFile("MultiOutput.txt", 8, true) 'i for appending, can create
f.WriteLine sLine
f.Close

nLoop = nLoop + 1
loop

WScript.Echo "done SubScript " &amp; nID &amp; " " &amp; nArg

set f = fso.OpenTextFile("MultiScripts.txt", 8, true) 'i for appending, can create
f.WriteLine "SubScript " &amp; nID &amp; " done"
f.Close

'===&lt;/pre&gt; &lt;br&gt;  &lt;br&gt; I'm going camping this weekend, so if I don't reply its because I'm trading computers for woods and snow for a little while. Will be back Tuesday. &lt;br&gt;  &lt;br&gt; -toddio </description><link>http://www.visualbasicscript.com/fb.ashx?m=18303</link><pubDate>Fri, 18 Mar 2005 23:10:04 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> Well, I'v considered that in the past and came to the conclusion that it was not any easier to do what I wanted to do (might just for me anyway) since the PING is just one of the process out of approximately 20 for each host that needed to run againsted. The problem with any asynchronized events is that it is darn difficult to track which event belongs to which originator. Of course, if you would only need to check the ping status (like what giantlunarmoth *originally* wanted to do, if I remembered that correctly, this thread is really hurting my head :P), async would work (most of the time). &lt;br&gt;  &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18302</link><pubDate>Fri, 18 Mar 2005 13:53:18 GMT</pubDate></item><item><title>Re: MULTITHREADING (kirrilian)</title><description> if i understand correctly this is what you guys are looking for. i have used it a few times to speed up wmi queries, its a pain but it works, &lt;br&gt;  &lt;br&gt; &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/making_an_asynchronous_call_with_vbscript.asp" target="_blank" rel="nofollow"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/making_an_asynchronous_call_with_vbscript.asp&lt;/a&gt; </description><link>http://www.visualbasicscript.com/fb.ashx?m=18301</link><pubDate>Fri, 18 Mar 2005 11:03:31 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> ahh..heh.. It's alright. We have lots confusion in this particular thread. Getting used to it =) &lt;br&gt;  &lt;br&gt; I guess you already know since it was discussed. Personally, I wouldn't do such things because, 1: it doesn't feel real (it runs minimized for me, so I didn't even see the window popup except very first one), and 2: it is proned to errors. &lt;br&gt;  &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18300</link><pubDate>Fri, 18 Mar 2005 10:07:29 GMT</pubDate></item><item><title>Re: MULTITHREADING (giantlunarmoth)</title><description> &lt;blockquote id="quote"&gt;&lt;font size="1" face="Verdana, Arial, Helvetica" id="quote"&gt;quote:&lt;hr height="1" noshade id="quote"&gt;&lt;i&gt;Originally posted by giantlunarmoth&lt;/i&gt; &lt;br&gt; &lt;br /&gt;Right, but do you know how the above script is simulating it?&lt;hr height="1" noshade id="quote"&gt;&lt;/blockquote id="quote"&gt;&lt;/font id="quote"&gt; was in response to: &lt;br&gt; &lt;blockquote id="quote"&gt;&lt;font size="1" face="Verdana, Arial, Helvetica" id="quote"&gt;quote:&lt;hr height="1" noshade id="quote"&gt;&lt;i&gt;Originally posted by token&lt;/i&gt; &lt;br&gt; &lt;br /&gt;I don't think you can appened any data using msgbox.&lt;hr height="1" noshade id="quote"&gt;&lt;/blockquote id="quote"&gt;&lt;/font id="quote"&gt;Sorry for the confusion...this was regarding the off-topic msgbox echo append simulation. </description><link>http://www.visualbasicscript.com/fb.ashx?m=18299</link><pubDate>Fri, 18 Mar 2005 09:57:32 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> &lt;blockquote id="quote"&gt;&lt;font size="1" face="Verdana, Arial, Helvetica" id="quote"&gt;quote:&lt;hr height="1" noshade id="quote"&gt;&lt;i&gt;Originally posted by giantlunarmoth&lt;/i&gt; &lt;br&gt; &lt;br /&gt;Right, but do you know how the above script is simulating it? &lt;br&gt; &lt;hr height="1" noshade id="quote"&gt;&lt;/blockquote id="quote"&gt;&lt;/font id="quote"&gt; &lt;br&gt;  &lt;br&gt; &lt;blockquote id="quote"&gt;&lt;font size="1" face="Verdana, Arial, Helvetica" id="quote"&gt;quote:&lt;hr height="1" noshade id="quote"&gt;&lt;i&gt;Originally posted by token&lt;/i&gt; &lt;br&gt; &lt;br /&gt;I didn't see where it simulated multithreading. Mind point that out ? &lt;br&gt; &lt;hr height="1" noshade id="quote"&gt;&lt;/blockquote id="quote"&gt;&lt;/font id="quote"&gt; &lt;br&gt;  &lt;br&gt; Mind point that out again ? =) &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18298</link><pubDate>Fri, 18 Mar 2005 07:53:29 GMT</pubDate></item><item><title>Re: MULTITHREADING (esnmb)</title><description> instead of appending the data to a msgBox, why not an IE window? </description><link>http://www.visualbasicscript.com/fb.ashx?m=18297</link><pubDate>Fri, 18 Mar 2005 07:16:33 GMT</pubDate></item><item><title>Re: MULTITHREADING (giantlunarmoth)</title><description> Yes...many tasks starting in the same &lt;b&gt;INSTANT&lt;/b&gt;. Who's got the logic? </description><link>http://www.visualbasicscript.com/fb.ashx?m=18296</link><pubDate>Thu, 17 Mar 2005 22:42:46 GMT</pubDate></item><item><title>Re: MULTITHREADING (token)</title><description> so..umm.. multithreading ? &lt;br&gt;  </description><link>http://www.visualbasicscript.com/fb.ashx?m=18295</link><pubDate>Thu, 17 Mar 2005 21:22:23 GMT</pubDate></item><item><title>Re: MULTITHREADING (giantlunarmoth)</title><description> I didn't mean to dilute the original topic of this thread. I saw a nifty parlor trick in that Ostrosoft script, and was curious how it worked. I thought it could help another user's thread, but should've posted it there instead. :) </description><link>http://www.visualbasicscript.com/fb.ashx?m=18294</link><pubDate>Thu, 17 Mar 2005 19:57:27 GMT</pubDate></item></channel></rss>
