Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to the BackgroundWorker Class and Multi-threading, but I think something like this is what I'm needing. I've got a program I've written in VB.Net that allows a user to load in several CAD parts into a ListView and perform several tasks like copy parts to a directory for nesting, create IGES files, create PDF's from drawings, and input part data into AS400 databases (BOM). The BOM entry takes the longest (about 30 to 45 seconds) because it loads a form that reads all parts belonging to the BOM and shows them in a TreeView to give the user the ability to select at what level the part should be inserted. What I would like to do is be able to open the BOM form after the user clicks the Process button and have it run in the background while all of the other stuff is processed, then have the BOM form show after everything else has been completed. I've Googled and read several articles regarding the BackgroundWorker Class and Multi-threading, but haven't found anything that pertained to an entire form. Any help will be appreciated. Thank you in advance.

Regards,
Shawn
Posted

I can't provide a lot of help on the subject because I'm just learning about this, but could you put the loading code in a sub/function declared async and call it using await (with the code to show the form somewhere after the function finishes)? If I've got the basic understanding of async/await figured out, that should do what you want. You'll, of course, want to do some research on your own to figure out exactly how to do it (and to see if I'm right, of course).
 
Share this answer
 
A background worker is a perfect choice for loading data in backgground. You can find a lot of information on them on the web and it not hard at all to make them work.

Typically, you can report progress every 1% of progress and update your UI at that (add processed item to the list and possibly update a progress bar).

Given that it take around 50 seconds now, your UI would be updated about twice per second with an update every 1% (it can also be every x items).

You can experiment with that. In your case, you will probably want more than an update per 1 percent increment since it is a very long processing.

You want to report progress often enough for smoothness but not too often to aftect the overall performance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900