I'm having trouble with my program flow in a while loop I created.
while (reader.Read())
{
// Store scenario information
int Id = (int)reader["ScenarioID"];
string Data = reader["ScenarioData"].ToString();
string Url = "http://google.com";
// Initialize result information
int HasSucceeded = 0;
var screenshot = new Byte[] { };
// Navigate to webBrowser
webBrowser2.Navigate(Url);
webBrowser2.DocumentCompleted += WebBrowserDocumentCompleted;
// Do test
TestScenarios(Url, HasSucceeded);
// Take screenshot
TakeScreenshot(screenshot);
// Insert results
InsertResults(Id, HasSucceeded, screenshot);
// Mark scenario for deletion
MarkScenario(Id);
}
private void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs Url)
{
MessageBox.Show("Operation has completed!");
}
The expected flow of the program should be
- Read an item in the table
- Initialize some variables/store some values
- Navigate the webBrowser control toe the URL
- When the webBrowser control is finished, do a test
- Take a screenshot
- Insert results into new table
- Mark the item in the original table for deletion
- Loop back to #1 until all items have been covered.
However, what is happening is everything in the while loop is running properly in order except for the webBrowser2.Navigate
line, which does not show the Url until the while loop has exited. Immediately after the Url shows, 5 sequential messages "Operation has completed" (for the 5 items in the table) appear. How can I fix my flow?