-4

I am going to make a facebook applications in c#. I extract group ids to textbox4.Text and i want to go to all website 2 seconds to 2 seconds.. it means 1 website display 2 seconds after 2 seconds it will redirect to another website...

I use timer to get 2 seconds duration and I want to go to all website using a loop or something.. I use for loop for that but it is not printing all website. it prints only website in last...

Here i extract group IDs this is working no problem

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    richTextBox1.Text = webBrowser1.DocumentText;
    textBox3.Text = string.Join(Environment.NewLine,
        richTextBox1.Text.Split('/', ' ', '?')
                .Where(m => m.Length > 14 && m.All(char.IsDigit)));
    label3.Text = (textBox3.Lines.Length).ToString()+" Groups";
}

problem is following code when i am going to launch these one by one.

private void button2_Click(object sender, System.EventArgs e)
{
    textBox3.Text = string.Join(Environment.NewLine,
        richTextBox1.Text.Split('/', ' ', '?')
            .Where(m => m.Length > 14 && m.All(char.IsDigit)));
}

IEnumerator<string> websites;

private void button3_Click(object sender, System.EventArgs e)
{
    textBox4.Text = textBox3.Text;
    string[] groups = textBox4.Text.Split('\n');

    for (int i = 0; i < textBox3.Lines.Length; i++)
    {
        websites = new List<string> {"https://mbasic.facebook.com/groups/"+groups[i]}.GetEnumerator();
        timer1.Enabled = true;
        websites.MoveNext();
    }
}

private void timer1_Tick(object sender, EventArgs e)
{
    webBrowser1.Navigate(websites.Current);
    timer1.Enabled = websites.MoveNext();
}

Please anybody fix this issues.

rweisse
  • 820
  • 10
  • 26

1 Answers1

0

I think you are overwriting your websites-object in every loop with the following line:

websites = new List<string> {"https://mbasic.facebook.com/groups/"+groups[i]}.GetEnumerator();

That's why it only prints the last website.

Have a look at How can I add an item to a IEnumerable collection?

Furthermore this could help you, too: IEnumerable vs. IEnumerator and implementation

rweisse
  • 820
  • 10
  • 26
  • yes. my code is wrong. I can see i am overwriting the code. I need to print https://mbasic.facebook.com/groups/"+groups[i] line in a loop to get all groups like https://mbasic.facebook.com/groups/"+groups[0],https://mbasic.facebook.com/groups/"+groups[1], https://mbasic.facebook.com/groups/"+groups[2], https://mbasic.facebook.com/groups/"+groups[3],...etc . do you have any idea to print like that? – Imashi Ekanayaka Dec 10 '17 at 18:40
  • Use List strings = new List(); – rweisse Dec 10 '17 at 18:51
  • Inside your for-loop add each url by: strings.add(url) – rweisse Dec 10 '17 at 18:53
  • Finally start your timer. Sorry for my bad code formatting. I'm using my mobile phone. – rweisse Dec 10 '17 at 18:54
  • In words: Add your url strings to a List. After that "initialize" your websites objects with this list. But do not use IEnumerator for websites. Better use IEnumerable – rweisse Dec 10 '17 at 18:58
  • hi i set as you said. please see, what is the wrong of this clicking [this](https://scontent.fcmb2-1.fna.fbcdn.net/v/t1.0-9/24909691_149915155774236_7907890880088530804_n.jpg?oh=91026e4c1b40cb86859dd09bfd8dbe09&oe=5AC05157) – Imashi Ekanayaka Dec 10 '17 at 19:04
  • websites = strings.AsEnumerable(); – rweisse Dec 10 '17 at 19:04
  • 1
    your method is right. i [FIX THE issue Click here](https://scontent.fcmb2-1.fna.fbcdn.net/v/t1.0-9/25289618_149916439107441_7614206290565424235_n.jpg?oh=df6b25686d8cdc9ca4c7eb3ecb6ac5d4&oe=5A9001E7) – Imashi Ekanayaka Dec 10 '17 at 19:08
  • Yes @Imashi-Ekanayaka fixed your foreach-loop the right way. But I think you should use .AsEnumerable(); instead of .getEnumerator() – rweisse Dec 10 '17 at 19:13