我有代码,每次发送消息时,它都会对其进行计数,然后设置状态。很简单,但是我在函数中添加了一些消息发送调用,因此它更快,现在显然计数已关闭,因为它在此示例中每四条消息计数一次:
private void messagespam_worker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i < numericUpDown1.Value; i++)
Invoke((MethodInvoker)delegate
{
foreach (Chat chat in skype.Chats)
{
if (messagespam_bool == false)
{
numericUpDown1.Value = 0;
break;
}
try
{
toolStripStatusLabel3.Text = "- Sent: " + i; // Where the status is changed
String contact = listBox1.SelectedItem.ToString();
skype.SendMessage(contact, textBox7.Text); //1st message
skype.SendMessage(contact, textBox7.Text); //2nd message
skype.SendMessage(contact, textBox7.Text); //3rd message
skype.SendMessage(contact, textBox7.Text); //4th message
}
catch (Exception error)
{
MessageBox.Show(error.Message);
}
break;
}
});
}
我希望上面的代码在每次发送消息时都计数:
skype.SendMessage(contact, textBox7.Text); //1st message
skype.SendMessage(contact, textBox7.Text); //2nd message
skype.SendMessage(contact, textBox7.Text); //3rd message
skype.SendMessage(contact, textBox7.Text); //4th message
发送消息 1 时,应将状态设置为 1,然后发送消息 2 时,应将状态设置为 2,依此类推。