I am stumped on this. Here is my scenerio.
>> = creates
>: = event kicked off
Class A >> Class B >> Class C
Class A >> Class D
When Class C creates a graphic object , alert Class A to tell Class D to reset all its data.
Class C >: Class B >: Class A
Class A has this code:
private
void Feature_DataChanged(object sender, EventArgs e){
ImageHandler image = (ImageHandler)sender;m_associationview.SetAssociation(image.Text);
}
m_associationview is the object that created Class D in Class A's constructor.
SetAssociation is a method in Class D.
FeatureAddEventHandler is a private delegate in Class D.
private
delegate void FeatureAddEventHandler(string image)public
void SetAssociation(string image){
this.Invoke(new FeatureAddEventHandler(this.SetAssociationData), new object[] { image });}
I am trying to Invoke Class D to reset all its textboxes, datagrid info, and comboboxes.
private
void SetAssociationData(string fullImage){
// set textboxes and comboboxes.
}
I get all the way from Class C to tell Class D to reset itself. But the Invoke will not work. I get this error:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
I don't know how the handle is not created. Class A creates class D on initiazation, its never destroyed.
I know this is some type of thread issue. Here I am trying to have a form throw an event to alert another form to update itself. Because it is not on the same thread, even though I can get into the code, once it exits the event, the form never updates. I was told that I can use the Invoke to solve my thread UI issue. Any ideas

Thread | Invoke Issue
qingxisong
The scenerio is started like this:
Class A is my main app.
Class B is instantiated in a Method in Class A. (Class B is a regular form handles images)
Class C is instantiated within a mouse down event in Class B. (Class C is a usercontrol that is layered over Class B, I draw graphics on this)
Class D is instantiated in the constructor of Class A so its always existing. (Class D holds a whole bunch of data)
Another update: this is all happening on the same thread...I checked.
I even passed a Class A object throughout the constructors and called the public method from it on Class D, and it got into the method, but nothing got set.
Dustin Campbell
It doesn't get us much futher, but it does confirm that Invoke is indeed throwing an exception for the right reasons.
So, your ClassD object has not had its handle created properly, or has been deleted. So, now we need to figure out why the handle hasn't been created or has been freed.
For another check (in the same place as the IsHandleCreated previous) can you detail what the value of the this.IsDisposed property is. I'm thinking the ClassD form may have been disposed by the time you've reached the Update method.
Also, can you confirm the value for the d_association.IsHandleCreated property in the ClassA.Feature_DataChanged method Also, confirm the value of d_association.IsHandleCreated right after the construction of ClassD in ClassA.ClassA()
Pietje_Gates
ISLAM AHMED
What is the value of the this.IsHandleCreated property in the beginning of ClassD.Update(String) (I'm assuming that the method giving you grief...)
MartinClayton
this.IsDiposed = false
d_association.IsHandledCreated = false in Feature_DataChanged();
d_association.IsHandledCated right after ClassD in the constructor of Class A is false as well.
Sowelie
I can't tell much from your description. My guess is that Class D is Form-based and it has been constructed by hasn't initialized property. Check its Handle property.
I would suggest not doing anything like this in the constructors of Form objects. Performing these actions in a Load event handler is safer; the Form and its children will have their handles created, under normal circumstances.
Ahmad Shawky
Well....okay...let me explain about Class D.
ClassD is a form that is instantiated in the constructor of ClassA. However, ClassA has a button event that shows the ClassD form.
Its:
private
void viewsAssociationMenu_Click(object sender, EventArgs e){
d_association.Show(dockManager1);
}
So I never set the Visible property on the form, but its not "shown" until the button is click. However, even when the form is visible on screen (after the operator clicks the button to show it), I still have the same problem.
That dockManager object is from WinFormsUI docking management. It basically allows me to dock the form like Visual Studio.
gregu33701
Peter -
Thank you for your help. I really appreciate it.
I believe I found the issue.
ClassB does not belong to Class A. Thats the issue.
Thanks again.
Craig Richardson
Mark Bailey
Well isn't ClassD already existing because its instantiated in the constructor of ClassA
ClassD is never disposed of fyi. It's always there until the actual application is exited.
I just don't understand why if I called d_association.Update( ) if my events follow back all the way to where the method is called...why it wouldn't set the data on ClassD form.
ecn i
It's really hard to help if only parts of the issue are given over time...
I still haven't gotten all the information; and the information is interspersed between a half a dozen posts making it really hard to help. I'm assuming; but, I think your issue is that you're raising the event that causes Update to be called on a MouseDown event, while the Click event isn't raised until the MouseUp... You're trying to do something with the control before it has been made visible.
Pauls1965
Is the ClassD visible when it is created or is it hidden Forms that aren't visible when they are created won't have their handle created upon construction. They're handle isn't created until they become visible.
This basically means that a control's handle isn't guarenteed to be created immediately after it is constructed.
Sandman13
Let me try to put it into code:
public class ClassA : Form
{
private ClassD d_association;
private ClassB b_handler;
public ClassA()
{
d_association = new ClassD();
}
public void ViewFile()
{
b_handler = new ClassB();
b_handler.FeaturesChanged += new ImageFeatureEventHandler(Feature_DataChanged);
}
private void Feature_DataChanged(object sender, EventArgs e)
{
ClassB bobj = (ClassB)sender; // casting
d_association.Update(bobj.tabtext); // tabtext is a string.
}
}