I have a Datagridview that contains few columns and data in each row. I need to regularly send complete Datagridview data, each row data one at a time, sequentially to a web browser in my application, which will actually append this row data to a URL of a website that will echo whatever data is appended to it. So for this purpose I used a timer which will send all the data once for every 10 seconds. Inside the timer to send each row one at a time I used the following for loop:
private void tmr_senddata_Tick(object sender, EventArgs e)
{
if(dg_parameters.Rows.Count!=1)
{
for (int i = 0; i < dg_parameters.Rows.Count-1; i++)
{
string row = "";
string cell = "";
for (int j = 0; j < dg_parameters.Columns.Count; j++)
{
cell = cell + dg_parameters.Rows[i].Cells[j].Value;
cell = cell + "@";
row = cell;
}
string uri = webBrowser1.Url + row;
webBrowser1.Navigate(uri);
}
}
}
Now what I end up is only the last row being displayed on the browser. This is because by the time my browser navigates to the URL specified for the first time in my loop, next iteration takes and URL changes. So only my last row data is navigated properly and displayed on browser. How do I stop the for loop for a specified time every time so that I can see my browser navigate to the URL. I believe Thread.Sleep() is not a good idea because it blocks my UI thread.
UPDATE: This is a simulation application used to test a particular scenario. So please ignore the reason in doing this. A solution to the problem will do good.
Put your
dg_parameters.Rowsin aQueuewhen your application starts.Each time the timer fires, call
myQueue.Dequeueto get the next item to use.