I am modifying an application written in C # that makes heavy use of multithreading to play audio files and display images for the user. Given that it is multithreaded, I often need to use the Invoke method to change form elements. I come across a template that I’m not comfortable with, where I find that I write frequent, small, delegated methods that usually do only one thing. An example of this is the following:
delegate void setImageCallback(Image img);
private void setImage(Image img)
{
this.pictureBox1.Image = img;
}
private void someOtherMethod()
{
...
if (this.pictureBox1.InvokeRequired)
{
this.Invoke(new setImageCallback(setImage), Image.FromFile("example.png");
}
else
{
this.pictureBox1.Image = Image.FromFile("example.png");
}
...
}
, , ? , , , "" .
.