Well i have tried what have you told me but unfortunately the problem is not here.I still got the freeze when i change the instances on the button click event of the main form application.
I'm going to try to give you more explanations of my code.
The first i have a main form which is the Application.Run(mainScreen)
On it there are only 2 buttons which when are clicked each of them is openig one instance of Class Form2.
i also have two background workers an they are both in infinitive loop collecting data and pasing it to one of the instances
BW1 is for form1 and BW2 is for form2.
i am passing the both forms via the e.Argument in the background worker call.
i also have an event which is called for each form when BW collects a package of data.The event updates the form and the BW collects than again and the process is in while(true) loop.
form the event i have beginInvoke and the visual studio doesn't report any error.
the instance is opened like this
private void Button1_Click(object sender, EventArgs e)
{
form1.Visible = true;
form1.Show();
}
the second instance is opened the same.
They are created in void main().
I tried to create them in class MainScreen but nothing changed.
here is the code for event in background worker which updates the instance.
this is in BW1:
form1.MyEvent += new MyDelegate(form1.OnEvent);
form1.clicked();
this is in class Form2:
public void clicked()
{
if (MyEvent != null)
{
if (this.InvokeRequired)
{
this.BeginInvoke(this.MyEvent);
}
else
{
MyEvent();
}
}
}
If you need more of code say so but there is a big bunch of it so i don't no what to show
Thanks!!!