J
Jeronimo Bertran
Hi,
I have a form with a pictureBox that should change from visible to not
visible depending on a status. The form receives events from a
communication thread in an object called commDriver.
In my form I register the event
commDriver.OnStatusReceived +=new StatusReceivedDelegate
(commDriver_OnStatusReceived);
Now, I am receiving the events just fine, I can also set the Text
property on the form's controls, however when I try to show or hide my
pictureBox, the application hangs.
I assumed that the problem had to do with having a different thread send
the event and not being able to update my control form a different
thread than the one used to create it.... so, I did the following:
private void commDriver_OnStatusReceived(object sender, string info)
{
if (myPicture.InvokeRequired)
{
// Update the status information asynchronously
UpdateStatusDelegate OnUpdateStatus = new
UpdateStatusDelegate(UpdateStatus);
OnUpdateStatus.BeginInvoke(info, null, null);
}
else
UpdateStatus(info);
}
And created the UpdateStatus method like this:
private void UpdateStatus(string info)
{
bool temp = myPicture.InvokeRequired;
// Do some work and....
// show or hide myPicture
myPicture.Visible = (info == "v");
}
For some reason the app still hangs when InvokeRequired returns true,
and I noticed that even though BeginInvoke is used,
myPicture.InvokeRequired STILL returns true.
Any ideas??
Thanks,
Jeronimo Bertran
I have a form with a pictureBox that should change from visible to not
visible depending on a status. The form receives events from a
communication thread in an object called commDriver.
In my form I register the event
commDriver.OnStatusReceived +=new StatusReceivedDelegate
(commDriver_OnStatusReceived);
Now, I am receiving the events just fine, I can also set the Text
property on the form's controls, however when I try to show or hide my
pictureBox, the application hangs.
I assumed that the problem had to do with having a different thread send
the event and not being able to update my control form a different
thread than the one used to create it.... so, I did the following:
private void commDriver_OnStatusReceived(object sender, string info)
{
if (myPicture.InvokeRequired)
{
// Update the status information asynchronously
UpdateStatusDelegate OnUpdateStatus = new
UpdateStatusDelegate(UpdateStatus);
OnUpdateStatus.BeginInvoke(info, null, null);
}
else
UpdateStatus(info);
}
And created the UpdateStatus method like this:
private void UpdateStatus(string info)
{
bool temp = myPicture.InvokeRequired;
// Do some work and....
// show or hide myPicture
myPicture.Visible = (info == "v");
}
For some reason the app still hangs when InvokeRequired returns true,
and I noticed that even though BeginInvoke is used,
myPicture.InvokeRequired STILL returns true.
Any ideas??
Thanks,
Jeronimo Bertran