Gohalien

Hi, I have 2 forms, one is main form, and the other one just have a webbrowser.

Code Snippet

public partial class Form1 : Form

{

public DataTable tablelinks = new DataTable();

public Web_form frmweb = new Web_form();

//Inside the Web form, I have a webbrowser with public access.

public Form1()

{

InitializeComponent();

tablelinks.Columns.Add("Links");

tablelinks.Rows.Add("http://www.microsoft.com");

tablelinks.Rows.Add("http://www.hotmail.com");

tablelinks.Rows.Add("http://www.google.com");

frmweb.Show();

for (int i = 0; i < tablelinks.Rows.Count; i++)

{

frmweb.webBrowser1.Navigate(tablelinks.Rows[i][0].ToString());

/* Now, here I want to add a delay of 30 seconds, to the user have

* that limited amount of time to watch the webpage in the list and then

* move into the next webpage in tablelinks, I have been trying with Timers

* with no success, and Thread.Sleep will just freeze the whole program and also

* the navigation, any solutions */

}

}

}



Re: Windows Forms General Trying to create a small "Delay"... but can't make it work

soujanya

Did you try using a timer with the interval for 30 seconds

You can specify the page to be opened in the timer_Tick. ............. this could be one of the solutions






Re: Windows Forms General Trying to create a small "Delay"... but can't make it work

Gohalien

Yes, that maybe a solution, but how do I send the value of "i" to the timer tick event since I am reading the links from tablelinks.RowsIdea[0]




Re: Windows Forms General Trying to create a small "Delay"... but can't make it work

boban.s

public partial class Form1 : Form

{

public DataTable tablelinks = new DataTable();

public Web_form frmweb = new Web_form();

private Timer timer = new Timer();
private int linkIndex = 0;

//Inside the Web form, I have a webbrowser with public access.

public Form1()

{

InitializeComponent();

tablelinks.Columns.Add("Links");

tablelinks.Rows.Add("http://www.microsoft.com");

tablelinks.Rows.Add("http://www.hotmail.com");

tablelinks.Rows.Add(http://www.google.com);

timer.Interval = 30000;
timer.Tick += OnThirtySeconds;
timer.Start();

frmweb.Show();
frmweb.NavigateLink(tablelinks.Rows[linkIndex][0].ToString());
linkIndex++;

}


private void OnThirtySeconds(object sender, EventArgs e)
{
if (linkIndex < tablelinks.Rows.Count)
{
frmweb.NavigateLink(tablelinks.Rows[linkIndex][0].ToString());
linkIndex++;
}
}

}

In the Web_form you will create public method:

public void NavigateLink(string link)
{
webBrowser1.Navigate(link);
}



This is one of many ways to do it. You can also pass the whole table in constructor of Web_form or set a property value, and move Timer and all code in that form.