Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoEvents (VB)

Status
Not open for further replies.

Toyman

Programmer
Jun 19, 2001
68
GB
Hi

Does java have a function like VB's doevents which allow one to give input to a user when in a while/for loop.

Lets say I want to process something. I want to give the user the option to cancel the process.(By Clicking on a button)

Thanks
Toyman VB / Java Programmer
cdt@icon.co.za
 
Hi,

I am quite new to Java, so i may be barking completely up the wrong tree here, but i think this may work.

Could you not do this with a couple of threads? One thread running the loop, and then have another thread opening a dialog with the cancel button on it. When the user presses the cancel button the ActionEvent can then set a flag to indicate to the loop thread that it should terminate its process?

I havent tried this, but i think it should work.
 
If I recall correctly, DoEvents is a wrapper around win32's Sleep function. Essentially, it puts your thread to sleep, so that other threads can run.

This doesn't make your app multithreaded, it's just a polite way to yield to other applications that need to get stuff done, saying hey, you guys go ahead for a split second.

In java, when you want to do this, you call Thread.yield(). This tells the current thread (which is the one you're calling from, right?), to give the other guys a chance to run.

Again, this doesn't make your app multi-threaded, it makes it more polite to other threads running.

If you are interested in multithreaded gui apps for Swing, do a google search for SwingWorker.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top