kbmMW Scheduler Tidbits #1

kbmMW contains a pretty powerful job scheduler which in next release of kbmMW becomes even more powerful.

It can execute things in a regular interval under various conditions.

But it can also be used for running code asynchronously without having manually to create threaded code.

Eg.

Scheduler.RunNow(
  procedure
  begin
    somelongrunningmethod;
  end);

The procedure will be executed immediately in a different thread, without blocking the executing of the current thread.

But sometimes you want the result of the asynchronous executing to be output to the GUI. And kbmMW’s scheduler now contains easy access to doing that.

var
  res:sometype;
begin
 Scheduler.Run(
   procedure
   begin
      res:=somelongrunningfunction;
   end)
  .SynchronizedAfterRun(
   procedure
   begin
     Memo1.Lines.Add(res);
   end)
  .Activate(true);

In this case, somelongrunningfunction is executed in a seperate thread, and its return value is placed in res. When the result is back, the code in SynchronizedAfterRun is executed, this time synchronized with the main thread, which makes it GUI safe.

Super easy way to execute async with support for updating GUI afterwards.

best regards

Kim/C4D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s