Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a sub that connects to a remote database to download records, could be 10 could be 10,000. I have a progress bar that shows the progress on which record its on, with a text to display a number 5/239. I have a "me.refresh" to keep the lable updating between records.

 

I have a cancel button on the form that when pressed, should set blnCancel to True. While my other sub is looping through the records, if it sees blnCancel = True then it should " throw new exception("Aborted") ". Maybe theres a better way then how im approaching this.

 

However. my problem lies in clicking the button. I can't click it. my app is too busy to listen for the click event. What should I do?

Posted
Adding Application.DoEvents() to the loop should allow the UI to still be used.
Anybody looking for a graduate programmer (Midlands, England)?
Posted

It sounds like you need to seperate the DB call out into a worker thread. The BackgroundWorker for .Net 2.0 is an easy way to do that. The catch is that you'll need to put a check in your method that downloads the records to keep an eye out for a cancel so that it knows when to terminate the thread (you can only politely request a background worker thread terminate.)

 

Check this thread out for an example: http://www.xtremedotnettalk.com/showthread.php?t=96990&highlight=backgroundworker

Posted
Thanks mskeel. I'm already using a few threads in my app with success. My only concern is being able to update the UI while the background worker is running. I'm found a difficult way to get around that in another area of my app, which can't apply to this scenerio. I will try the application.doevents. it sounds like it will work.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...