Scheduler Suggestions

Home Forums kbmMW Scheduler Suggestions

Viewing 1 reply thread
  • Author
    Posts
    • #56546
      Babis Michael
      Participant

      Hello,

      1) RunNow doesn’t capture the local variables (out of RunNow)
      2) Need a ExecuteAsync non-blocking function.
      3) Need a Thread Priority parameter

      Also trying to change “Active” property from another Scheduled thread causes deadlock is this is normal ?

      Thank you

    • #56549
      kimbomadsen
      Keymaster

      1) Variable capturing is a feature of Delphi, and it should work regardless of how the anonymous function is used, as long as it is within scope of the running code. Since the function must be in scope when you run it (otherwise you would get an A/V), the captured variables ought to be live too. If not it is a bug in Delphi.

      However you can use the Withxxxx(..) methods to include data to your scheduled task. You can access that data from the AEvent instance’s Data, &Object or &Interface properties in the event procedure.

      2) That is what RunNow does. It schedules an event to run async as soon as possible. You can force it to run sync using the Synchronized or SyncQueued setting, but you can also use InAMoment which is the same as RunNow but which will queue the event on the main thread (typically for visual updates).

      3) Hmm… there are 3 types of threads handled by the Scheduler: a) The main VCL thread, b) pool of threads for precise events, c) pool of threads for relaxed events

      a is governed by the VCL. b and c respectively require all threads to run with same priority. b has no limits on the number of allocated system threads, while c has.

      Generally it is not recommended to make changes to scheduled events active state from within a scheduled event.
      Instead set its pause property, as this will not interfere with its spooling up/down, but will prevent it from being run if not already running.

      • #56550
        Babis Michael
        Participant

        Hello,

        1) Well replaced TThread.Queues with Scheduler.RunNow (SyncQueued) but it resulted in AV due the missing capture of variables. Seems Delphi is only capturing for TThread classes. I’ve used the Withxxxx in the past but it’s more complex compared letting the compiler capturing the variables. IOW more code
        2) Sure but it more easier and nicer for the coder to write “ExecuteAsync or AsyncExecute” rather Scheduler.RunNow(procedure begin MyScheduledEvent.Execute end);
        3) I meant for Pool threads (not vcl). Eg we can set a parameter for the thread priority to apply it before execute and after the termination it to reset to normal thread priority. Anyhow i can’t find a reason why it can’t be done cause it doesn’t conflict with other threads nor the pool itself.

        Thank you for the quick responses 🙂

Viewing 1 reply thread
  • You must be logged in to reply to this topic.