Guides/Asynchronous GUI

From J Wiki
Jump to: navigation, search

Wm yes check.png

Problem of asynchronous GUI updates arises when executing long running processes and the GUI needs to appear responsive to the user.

Examples of asynchronous GUI include update/download managers: browser download tool windows (Firefox, Safari); software update tools (Windows Update, Apple Update). Also there are long-time processing apps like CD/DVD burners, movie makers and converters, etc.

In J besides external processes there may be other uses: process management, where the calculation job is split into separate tasks, whose execution can be shown or interacted in GUI; searches as in Find in Files can benefit from more responsive updates.

<!> Asynchronous stands for the first letter of AJAX.

J Processing

In J most calculations are done on the thread of the GUI message loop. This means that if they take long, the GUI does not have a chance to refresh quickly enough, which creates the perception of being not responsive, frozen to the user.

We will look at some solutions below.

ISI Graph Control

isigraph control has the glpaint method, which can update the control many times during the event handling cycle.

GUI Update

The underlying platform window managers typically have methods to force GUI update during the event handling cycle.


UpdateWindow function from user32 can be used with parent HWND parameter. It has wd equivalent setupdate.

  HWNDP=: 0".wd 'qhwndp'
  'user32 UpdateWindow > n i'(15!:0)HWNDP

Starting with j601

There is a new wd command msgs that works both in Windows and Java. It allows to have multiple refreshes during event handling for both isigraph and standard controls.

See attached example. Comment out the wd 'msgs' line to see the effect. <!> The isigraph control is not needed for GUI agility, as all regular controls will be updated. It is given in the example for illustration.

See Also

Contributed by Oleg Kobchenko