Exception-When minimized and restored
-
I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance
-
I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance
All interaction with a control should be done on the thread on which the control was created. The
Control.InvokeRequired
property and theControl.Invoke
method are for this very thing. You could load the image in a separate thread, but when you assign the image to aPictureBox
, for example, you should do it in the control's owner thread:void AssignImage(Image img)
{
if (!pictureBox1.InvokeRequired)
{
pictureBox1.Image = img;
}
else
{
MethodInfo setMethod = pictureBox1.GetType().GetProperty("Image").GetSetMethod();
MethodInfoInvokeHandler d = new MethodInfoInvokeHandler(setMethod.Invoke);
pictureBox1.Invoke(d, new object[] {pictureBox1, new object[] {img}});
}
}
delegate object MethodInfoInvokeHandler(object obj, object[] parameters);Interacting with a control from a different thread causes unusual problems that differ from control to control and even between properties and methods for a single control. I'm not 100% sure this is the problem you're seeing but it's one possibility. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]
-
I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance
What Heath said is probably what is happening, but you can also get those errors if you Dispose the image before the PictureBox gets a chance to draw it. Regards Senthil _____________________________ My Blog | My Articles | WinMacro