0

I am running on a new project which needs to navigate through a WebBrowser control to make login, click on some links, extract data and download pictures. As you can suppose, it takes too much time and it supposes to freeze the application while it is working. To avoid that, I thought on BackgroundWorker to leave it in the background but I found this thread which says that it is not recommended.

Considering that the project, basically, is based on navigate in a website once I click a button, what should be the correct way to make it useful? I've never used BackgroundWorker but I would like to learn it, so this could be a good moment.

Community
  • 1
  • 1
smt
  • 267
  • 6
  • 22
  • 1
    It's not recommended to do so, no. If what you're doing is a non-repeating process (i.e. it doesn't start over when it has done everything, unless you click the button again) you should be able to use the `DocumentCompleted` event. See this: http://stackoverflow.com/a/42366199/3740093 (though actual heavywork/heavy processing should still be done in a Task/Thread/BGW) – Visual Vincent Apr 04 '17 at 00:34
  • **TL;DR:** Create a new `DocumentCompleted` event handler every time the WebBrowser needs to load something or navigate to a new page, then remove that handler from within itself when it is raised to stop it from running another time unless you start everything from the beginning. – Visual Vincent Apr 04 '17 at 00:36
  • It's a repeating process. It should read a list of values and working based on it using a loop. – smt Apr 04 '17 at 00:37
  • How often should it read this list? All the time or shall it process the entire list before starting over? If the latter, then you can still use my solution. Just have your code add the first `DocumentCompleted` event handler again and redirect it when it is to start over. – Visual Vincent Apr 04 '17 at 00:38
  • It reads the list just when starting over. It makes more than one load. I mean, once it gets the value of the list, it is used in a search bar (so it reloads the WebControl when it clicks in a submit button), and then it finds automatically the result I need, click on it (new page, new reload) and finally extract all the information. It needs 3 reloads with different actions between them. I don't know if it can be handled. – smt Apr 04 '17 at 00:50
  • Ok, then my solution will work. Just make different `DocumentCompleted` event handlers for each action and subscribe/unsubscribe them accordingly inside one another. There's an example project in the answer that I linked you to. – Visual Vincent Apr 04 '17 at 01:04
  • I will try as soon as I can and come back to you with a feedback. Thanks for your help! – smt Apr 04 '17 at 01:18

0 Answers0