L
Laurent Navarro
Hello,
I created an application with the FrameWork 1.1 containing differents
forms and threads runing. There was no problem, I could click on a picture
on my Main Form to call the Show() function of another form without problem.
Then I installed Visual Studio 2005 and the FrameWork 2.0. I launched my
application and I had lots of error saying I was crossing the thread calls
when clicking on the picture of my Main Form or calling the BeginInit()
function of a custom control containing a TreeView.
I read the MSDN and found the
System.Windows.Forms.CheckForIllegalCrossThreadCalls parameter and set it to
false. It is now working but I know that it is just a trick hiding some
mistakes in my source code.
My question is: do I have to create delegates each time I want to use a
function of a form or a control from another form or thread ? If I want to
call the Show() function of a form from my Main Form, do I have to create on
the child form a delegate and a new NewShow() function like this (for
example):
public classe MyForm : System.Windows.Forms.Form
{
private delegate void show(void);
public void NewShow()
{
if (this.InvokeRequired)
{
this.Invoke(new show(base.Show(void)));
}
else
{
base.Show();
}
}
}
It is just an example, the syntaxe may be incorrect but the idea is
here. Prehaps did I miss something and I hope someone will be able to help
me !
Thank you
Laurent
I created an application with the FrameWork 1.1 containing differents
forms and threads runing. There was no problem, I could click on a picture
on my Main Form to call the Show() function of another form without problem.
Then I installed Visual Studio 2005 and the FrameWork 2.0. I launched my
application and I had lots of error saying I was crossing the thread calls
when clicking on the picture of my Main Form or calling the BeginInit()
function of a custom control containing a TreeView.
I read the MSDN and found the
System.Windows.Forms.CheckForIllegalCrossThreadCalls parameter and set it to
false. It is now working but I know that it is just a trick hiding some
mistakes in my source code.
My question is: do I have to create delegates each time I want to use a
function of a form or a control from another form or thread ? If I want to
call the Show() function of a form from my Main Form, do I have to create on
the child form a delegate and a new NewShow() function like this (for
example):
public classe MyForm : System.Windows.Forms.Form
{
private delegate void show(void);
public void NewShow()
{
if (this.InvokeRequired)
{
this.Invoke(new show(base.Show(void)));
}
else
{
base.Show();
}
}
}
It is just an example, the syntaxe may be incorrect but the idea is
here. Prehaps did I miss something and I hope someone will be able to help
me !
Thank you
Laurent