Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run a proc at background ? 2

Status
Not open for further replies.

dotaliu

Technical User
Mar 25, 2008
15
CN
for example:
proc a {} {
...
}
proc b {} {
puts "step 1"
a
puts "step 2"
}
Is there a way to run proc a at background ?
 
I don't think you're question is well formed. If Tcl is running in the foreground, well, then it is. I think what you want is for proc a to run in a separate thread. I've never used threads, myself, but I'm told they can be terribly effective. See:
_________________
Bob Rashkin
 
thanks for Bong reply. Being a newhand, some question is not professional. I don't want to use complicate multi-thread , so your answer is enough.
 
A way to do that is as follows:
Code:
proc a {} {
  global myafter msec
  ...
  set myafter [after $msec a]
}
Proc [tt]a[/tt] need be called once (and only once) by your code where you need to start it, and [tt]$msec[/tt] should not be zero, otherwise the rest of the code won't execute. [tt]myafter[/tt] is a handle that allows you to stop the loop somewhere else in the code with [tt]after cancel $myafter[/tt] . And of course if proc [tt]a[/tt] is resource consuming, it will slow down the rest of the code performed actions...

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top