I am using some delegates to show or change something on form in a thread. Event method is like below.
private void PictureBoxImageSet(PictureBox PictrBox, Image Img)
{
try
{
PictrBox.BeginInvoke((ThreadStart)delegate()
{
PictrBox.Image = Img;
});
Thread.Sleep(FORM_ITEM_INVOKE_TASK_SLEEP_VALUE);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Do i always have to use Thread.Sleep() method? If i remove this, how will my software be affected from this change? What will be thread sleep value will be in these kind of events?
The code from where the function PictureBoxImageSet is called will conitnue further execution without delay of times used in thread.sleep.
If you are using an event on picture change then that may impact if some other thread do some job on basis of picture data.
If you want to synchronously completed this job then Call PictrBox.Invoke method and remove thread.sleep. it will guarantee to set the image before further execution of code.