Trouble with drawing on winfrom in new thread
-
Thread th = new Thread(delegate() { e.Graphics.DrawEllipse(new Pen(Brushes.Aqua, 10), new Rectangle(20, 20, 20, 20)); //this line throw new exception "Invalid argument" }); th.Start(); help pls
I suggest you carefully read the following two little articles: http://www.perceler.com/articles1.php?art=animation1[^] http://www.perceler.com/articles1.php?art=crossthreads1[^] :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
-
Thread th = new Thread(delegate() { e.Graphics.DrawEllipse(new Pen(Brushes.Aqua, 10), new Rectangle(20, 20, 20, 20)); //this line throw new exception "Invalid argument" }); th.Start(); help pls
First you are not passing the eventargs variable e into the delegate function. Secondly, you cannot perform GUI operations from any thread except for the one on which the form was created.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
First you are not passing the eventargs variable e into the delegate function. Secondly, you cannot perform GUI operations from any thread except for the one on which the form was created.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Just because you can do it doesn't mean it's a good idea. You're still going to run into issues somewhere down the line. You absolutely cannot do any drawing to the controls on a thread other than the one the control was created on.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...