473,381 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

propertygrid throwing error "Controls created on one thread cannot be parented to a control on a diffrent thread."

In my application I have two threads.
Each of them creates a new propertygrid.
In the property grid I have a property with a color editor.

Whenever i am clicking on the combo box to change the 'Color' in the
first thread is fine.

Any other thread that tries to modify the color in the property grid
throws:
"Controls created on one thread cannot be parented to a control on a
diffrent thread."

Is property grid thread safe? Is there any wrong static variable that
should be threadstatic? Any solution?

Thanks,

jaire
Nov 16 '05 #1
10 3358
jaire <ja*****@eresmas.com> wrote:
In my application I have two threads.
Each of them creates a new propertygrid.
In the property grid I have a property with a color editor.

Whenever i am clicking on the combo box to change the 'Color' in the
first thread is fine.

Any other thread that tries to modify the color in the property grid
throws:
"Controls created on one thread cannot be parented to a control on a
diffrent thread."

Is property grid thread safe? Is there any wrong static variable that
should be threadstatic? Any solution?


Any one form should only have controls created on one thread. You
should only ever access those controls from that thread, apart from
calling Control.Invoke, Control.BeginInvoke, Control.CreateGraphics and
Control.InvokeRequired.

See
http://www.pobox.com/~skeet/csharp/m...#windows.forms

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks for your quick reply but I think I was not clear:

My application creates two threads.
Each thread creates a form.
Each form creates a property grid.
The color editor is only accessed from his respective thread.

The problem looks like there is something cached on the ColorUI.
Although each property grid is created in a different thread, the
ColorEditor created by reflection ([Editor(typeof(ColorEditor),
typeof(System.Drawing.Design.UITypeEditor))])
is always the same.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Jesus Arevalo <ja*****@eresmas.com> wrote:
Thanks for your quick reply but I think I was not clear:

My application creates two threads.
Each thread creates a form.
Each form creates a property grid.
The color editor is only accessed from his respective thread.

The problem looks like there is something cached on the ColorUI.
Although each property grid is created in a different thread, the
ColorEditor created by reflection ([Editor(typeof(ColorEditor),
typeof(System.Drawing.Design.UITypeEditor))])
is always the same.


Hmm, possibly.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Example:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
using System.Data;

namespace ExamplePropertyGrid
{
public class Myobject
{
Color m_color;

public Myobject ()
{
m_color = Color.Black;
}

public Color MyColor
{
get
{
return m_color;
}
set
{
m_color = value;
}
}
}

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

Myobject myobject = new Myobject();
propertyGrid1.SelectedObject = myobject;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.SuspendLayout();
//
// propertyGrid1
//
this.propertyGrid1.CommandsVisibleIfAvailable = true;
this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid1.LargeButtons = false;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(292, 273);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.Text = "propertyGrid1";
this.propertyGrid1.ViewBackColor =
System.Drawing.SystemColors.Window;
this.propertyGrid1.ViewForeColor =
System.Drawing.SystemColors.WindowText;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.propertyGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Thread thread1 = new Thread(new ThreadStart(NewMain));
// start study in new thread so that database connection is unique.
thread1.Start();

Thread thread2 = new Thread(new ThreadStart(NewMain));
// start study in new thread so that database connection is unique.
thread2.Start();
}

internal static void NewMain()
{
Application.Run(new Form1());
}
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Make sure your second thread runs his own message pump and is initialized
for STA.

Willy.

"Jesus Arevalo" <ja*****@eresmas.com> wrote in message
news:ua**************@tk2msftngp13.phx.gbl...
Thanks for your quick reply but I think I was not clear:

My application creates two threads.
Each thread creates a form.
Each form creates a property grid.
The color editor is only accessed from his respective thread.

The problem looks like there is something cached on the ColorUI.
Although each property grid is created in a different thread, the
ColorEditor created by reflection ([Editor(typeof(ColorEditor),
typeof(System.Drawing.Design.UITypeEditor))])
is always the same.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #6
Jesus Arevalo <ja*****@eresmas.com> wrote:
Example:


<snip>

Thanks. It certainly shows the problem up - and adding [STAThread] to
NewMain doesn't fix it either. I'll investigate and see if I can come
up with anything...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
Not sure why you need the same property browser object (Color) in two
separate threads of one application?
Or the color picker object was not designed to be used in such scenario, or
it's a bug.
There is no such problem if the objects are different components (f.i Color
and Font).
What exactly are you trying to achieve?

Willy.

"Jesus Arevalo" <ja*****@eresmas.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
Example:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
using System.Data;

namespace ExamplePropertyGrid
{
public class Myobject
{
Color m_color;

public Myobject ()
{
m_color = Color.Black;
}

public Color MyColor
{
get
{
return m_color;
}
set
{
m_color = value;
}
}
}

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

Myobject myobject = new Myobject();
propertyGrid1.SelectedObject = myobject;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.SuspendLayout();
//
// propertyGrid1
//
this.propertyGrid1.CommandsVisibleIfAvailable = true;
this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid1.LargeButtons = false;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(292, 273);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.Text = "propertyGrid1";
this.propertyGrid1.ViewBackColor =
System.Drawing.SystemColors.Window;
this.propertyGrid1.ViewForeColor =
System.Drawing.SystemColors.WindowText;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.propertyGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Thread thread1 = new Thread(new ThreadStart(NewMain));
// start study in new thread so that database connection is unique.
thread1.Start();

Thread thread2 = new Thread(new ThreadStart(NewMain));
// start study in new thread so that database connection is unique.
thread2.Start();
}

internal static void NewMain()
{
Application.Run(new Form1());
}
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #8
I have just created this piece of code to reflect my problem. My
application is a little bit more complex ;), where I can open like
multiple documents and each document needs to be opened in a separate
thread. Each document contains plots and the plots are controlled by
property grids to modify some properties.

..net gurus I need your help!!!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9
Jesus Arevalo <ja*****@eresmas.com> wrote:
I have just created this piece of code to reflect my problem. My
application is a little bit more complex ;), where I can open like
multiple documents and each document needs to be opened in a separate
thread. Each document contains plots and the plots are controlled by
property grids to modify some properties.


Out of interest, why do you particularly *need* each document to be in
a separate thread? Most applications keep all UI stuff in a single
thread, which would get rid of your problem, I'm sure. I still don't
know why it's failing, but unless there's a compelling reason for
keeping different documents in different threads, I'd consider
redesigning.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10
Ok, we know there is a problem with the color picker control, but can you
tell us what control(s) you have on your grid, and what control throws the
error?
Also I'm still not clear why you need two UI threads, even if you like to
open each document in his own thread, you should stick with one single UI
thread.

Willy.

"Jesus Arevalo" <ja*****@eresmas.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have just created this piece of code to reflect my problem. My
application is a little bit more complex ;), where I can open like
multiple documents and each document needs to be opened in a separate
thread. Each document contains plots and the plots are controlled by
property grids to modify some properties.

net gurus I need your help!!!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SS | last post by:
Can I change the font and backcolor of individual cells of a propertygrid control ?? And what if I want to make this change row-wise?? Say, show diff prop in diff colors??
1
by: James Divine | last post by:
Greetings all, I am using a PropertyGrid control in my application and I'm having trouble finding documentation on it. I have my basic PG built and can add Properties of standard types (int,...
2
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
0
by: Daniel | last post by:
How can I change the background color and font of individual cells in propertygrid control ?
0
by: micro_bug | last post by:
Now I am developing a tool, just like VS.net Form Edition environment. User can edit a component's properties by a PropertyGrid control. Now I have some questions about this PropertyGrid control:...
1
by: S.mark | last post by:
Hi, I can't find the ReadOnly property in PropertyGrid control (Visual Studio 2005), is there any work around to display object properties with the new PropertyGrid control in ReadOnly mode ? ...
1
by: Jéjé | last post by:
Hi, there is 1 or 2 years, I've found a webcontrol which provides the same propertygrid control (windows control) functionalities, but in an ASP.NET page. So this control allow me to edit...
0
by: Wilmer Rignack | last post by:
How may i include linklable in propertygrid control? anyone have the answer? send me an email to wrl711222@hotmail.com thanks Wilmer
7
by: siddhiash | last post by:
Hi Friends I want to add PasswordChar Property which shows ****** for string which I type in PropertyGrid Control. Regards, Siddharth
0
by: Richy | last post by:
Hi, I am running VB Express 2005 and have been developing an application fine under Windows XP, but now I have switched to WIndows Vista I am getting strange behaviour with the PropertyGrid...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.