(, ). static , :
private static void SomeMethod(ListBox listBox)
{
listBox.Items.Add("Some element");
}
... :
SomeMethod(MyListBox);
( winforms). BackgroundWorker ( SO; ). , , :
private void SomeMethod()
{
string newElement = FetchNextElementToAdd():
SafeUpdate(() => yourListBox.Items.Add(newElement));
}
private void SafeUpdate(Action action)
{
if (this.InvokeRequired)
{
this.BeginInvoke(action);
}
else
{
action();
}
}
... :
Thread thread = new Thread(SomeMethod);
thread.Start();
( , , , ):
ThreadPool.QueueUserWorkItem(state => SomeMethod());