Processing pending events from within a longl lasting loop (because user wants to cancel a search)

  • Thread starter Alexander van Meerten
  • Start date
A

Alexander van Meerten

Hello,

I have to make an application that works on pc and apple mac.
Therefore I am investigating if it's possible to use html/javascript.
The database has 10000 records and is sequentially searched. This may
take 20 seconds or so. I want the user to be able to quit the search
and also I want the outputscreen to be updated immediately when a hit
is found and not wait until the complete search is finished.

The problem is that the click-event of the 'Cancel-button' is
processed after the search is finished. Is there something like
application.processmessages (similar to Delphi) so all pending events
are processed?

Thanks for helping,
Alexander
 
J

Janwillem Borleffs

Alexander van Meerten said:
Hello,

I have to make an application that works on pc and apple mac.
Therefore I am investigating if it's possible to use html/javascript.
The database has 10000 records and is sequentially searched. This may
take 20 seconds or so. I want the user to be able to quit the search
and also I want the outputscreen to be updated immediately when a hit
is found and not wait until the complete search is finished.

When a search of just (yes, just) 10000 records takes up as much as 20
seconds, either a design flaw or a performance issue is really your problem.

When the user has clicked the submit button, the cached page is already left
and pressing the cancel button will only show the page which is generated on
the server at that time when you are lucky. Try to fix the problems
server-side, like limiting the number of results to, say, 10 per page,
because client-side JavaScript cannot solve it for you...


JW
 
A

Alexander van Meerten

Hi JW,

The application is an adressbook which will be distributed on a cd.
The application will be totally client-based. No server involved. The search
will be done in a javascript array.
So there will be no submit. The users fills in the query values in frame1
and presses the 'Search' button. Than there is a loop which generates
document.writes() with hitresults in frame2. I want these results to be
displays immediately and also that the users is able to abort the loop.
Esspecially when there are a lot of hits and the array is large (>10000)
this may take more time than the user is willing to wait.

Alexander
 
J

Janwillem Borleffs

Alexander van Meerten said:
Hi JW,

The application is an adressbook which will be distributed on a cd.
The application will be totally client-based. No server involved. The search
will be done in a javascript array.

In that case, you will have to resort to some kind of multitasking, which is
provided by the setTimeout() function.

I have prepared a basic implementation at the following URL:

http://www.jwscripts.com/playground/search2/


HTH,
JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top