Disable the timer as soon as the
timer1_Tick
procedure is entered. Re-enable the timer only if there are items left in the ListBox. In your code, if the
jabber.Send
takes more than four seconds, another
timer1_Tick
procedure will start running before the previous one has ended. I believe, that is the cause of your error.
Also, do not start the timer until the interval has been set.
private void button1_Click(object sender, EventArgs e)
{
jabber.Send("<iq type="get" to="" + textBox1.Text + "@conference.jabber.com" id="qip_1026"><query xmlns="http:
}
private void button2_Click(object sender, EventArgs e)
{
progressBar1.Maximum = listBox1.Items.Count;
progressBar1.Value = 0;
timer1.Interval = 4000;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = False;
if (listBox1.Items.Count > 0)
{
jabber.Send("<iq type="set" to="" + textBox7.Text + "@conference.jabber.com"><query xmlns="http:
listBox1.Items.RemoveAt(0);
progressBar1.Value += 1;
label.Text = listBox1.Items.Count.ToString();
}
if (listBox1.Items.Count > 0)
{
timer1.Enabled = True;
}
}