0

My algorithm automatically fills metadata in a specific website (using webBrowser). After fill metadata the algorithm press the button send (in website) and it must wait a few seconds for metadata to be analyzed before contiune (this is not part of algorithm, but webpage). The problem is that i have no way to know when metadata analsys finish. I try the next code, which is used to wait for fully loaded webpage before continuing with the processes:

webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

But it's useless becuse metadata analysis is not related to webpage loading.

So, because metadata analysis takes about 20-40 seconds i think that wait about 60 seconds and continue is a good solution. I try:

System.Threading.Thread.Sleep(60000);

After programmatically press button "send", but for anyreason this wait for 60 seconds before button is pressed.

1 Answers1

0

I don't think I completely understand why you're wanting to do what you're asking for here, so I'm attempting to answer this question with what information I have here.

If you're calling Thread.Sleep in an event handler (say, an event handler for a Button's click event), Thread.Sleep will effectively pause the program, since you're still on the UI thread. I'm guess this isn't what you're after?

If you want the UI thread to continue (where you're probably doing the bulk of your work), you'll need to make the Button's click handler async, and use await Task.Delay instead. You can see the pattern in use here: Should I avoid 'async void' event handlers?

Additionally, you can probably figure out a way to call back into your application using techniques detailed here: http://www.codeproject.com/Articles/35373/VB-NET-C-and-JavaScript-communication

Using that method, I'm sure you can get rid of the waiting altogether.

Community
  • 1
  • 1
Michael Nero
  • 1,396
  • 13
  • 24