多线程更新UI
private delegate object GetButtonTagDelegate(ref Button b);
private object GetButtonTag(ref Button b)
{
if (InvokeRequired)
{
return Invoke(new GetButtonTagDelegate(GetButtonTag), new object[] {b});
}
return b.Tag;
}
private delegate int GetComboBoxSelectedIndexDelegate(ref ComboBox cb);
private int GetComboBoxSelectedIndex(ref ComboBox cb)
{
if (InvokeRequired)
{
return (int) Invoke(new GetComboBoxSelectedIndexDelegate(GetComboBoxSelectedIndex), new object[] {cb});
}
return cb.SelectedIndex;
}
private delegate void ButtonPerformClickDelegate(ref Button b);
private void ButtonPerformClick(ref Button b)
{
if (InvokeRequired)
{
Invoke(new ButtonPerformClickDelegate(ButtonPerformClick), new object[] {b});
}
else
{
b.PerformClick();
}
}
private delegate void UpdateCountdownProgressBarDelegate(ref ProgressBar pb, int delay, int elapsed);
private void UpdateCountdownProgressBar(ref ProgressBar pb, int delay, int elapsed)
{
if (InvokeRequired)
{
Invoke(new UpdateCountdownProgressBarDelegate(UpdateCountdownProgressBar), new object[] {pb, delay, elapsed});
}
else
{
pb.Minimum = 0;
pb.Maximum = delay;
if (elapsed < delay)
{
pb.Value = delay - elapsed;
}
else
{
pb.Value = 0;
}
}
}
private delegate bool GetCheckBoxCheckedDelegate(ref CheckBox cb);
private bool GetCheckBoxChecked(ref CheckBox cb)
{
if (InvokeRequired)
{
return Convert.ToBoolean(Invoke(new GetCheckBoxCheckedDelegate(GetCheckBoxChecked), new object[] {cb}));
}
return cb.Checked;
}
private delegate void AddComboBoxItemDelegate(ref ComboBox cb, string item);
private void AddComboBoxItem(ref ComboBox cb, string item)
{
if (InvokeRequired)
{
Invoke(new AddComboBoxItemDelegate(AddComboBoxItem), new object[] {cb, item});
}
else
{
cb.Items.Add(item);
}
}