On 10/14/05, Harry <[EMAIL PROTECTED]> wrote: > Hi guys, > > I am not sure where to post this questions. Hopefuly > you guys are able to answer my questions: > > I am developing a simple applications using Thread > class to change the color of the square (Lab > assignment) > > everything working correctly, accept I have to drag > the windows in linux to let the Thread working to > change the color of a square. > > > here is my code: > using System; > using System.Windows.Forms; > using System.Threading; > using System.Drawing; > > public void Run() > { > Random r = new Random(); > while(true) > { > c = Color.FromArgb(r.Next(256), r.Next(256), > r.Next(256)); > Thread.Sleep(200); > } > } > > } >
I do not know in mono, but in .Net this is not the right way to do it. All properties and methods of Form class _ARE NOT_ thread safe. You can not touch them from a different thread (i.e. you can :) but it will have unexpected behaviour). The only methods which can be used from a different thread are BeginInvoke, EndInvoke, Invoke and the property IsInvokeRequired. You have to create a method which changes the the Color property, and call this method through a delegate with Invoke. This will dispatch the calling in the main GUI thread. Take a look here: <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp> Cheers -- Svetoslav Milenov (Sunny) _______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list