New Thread Manager Simplified

new topic     » topic index » view thread      » older message » newer message

Hello again,


I took Pete's advice and wrapped CheckThread() and another call into
a single call so as to simplify the 'Thread Manager' even more.

Here's what a typical app might look like with the new function call:
(now only three function calls are necessary)

function onClickButton(...)
  atom void

  StartThread(TimeSlice) --start a new thread for this new operation
  for k=1 to 10000000 do --arbitrary large number of chunks
    void=time() --kill some time for the demo (this would be 1 chunk)
    if QueryQuitThread(TimeSlice,0) then
      exit
    end if
  end for
  EndThread() --the operation ended so end this thread
  return 0
end function

Pretty simple if you ask me:)


Note that QueryQuitThread() with second parameter=0 always returns
a zero (0) so 'exit' can always be within the if/then statement.
If you want to allow the user to be able to exit the program, call
instead QueryQuitThread(TimeSlice,1) and leave everything else the same.
For app functions that cant be allowed to exit however call
QueryQuitThread(TimeSlice,0) such as for file saves.


Here's the new function that is added to ThreadManager01.ew at the
bottom of the file:


global function QueryQuitThread(atom TimeSlice,atom AllowAppQuit)
  --AllowAppQuit=1 to allow app to quit, 0 to stop app from quitting

  if CheckThread() then
    if QueryQuitMessage(AllowAppQuit) then
      return 1
    end if
    ContinueThread(TimeSlice)
  end if
  return 0
end function


I've checked this with the ThreadingDemo01.exw file and it works
the same as the old way, but remember that ThreadManager01.ew has
to be included in a manner similar to that demo if you write your
own program (like after some of the other includes) because it
calls QueryQuitMessage() which is in one of the other includes.


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu