thrad CLR problem

hi guys.i have problem with thread in clr i have one thread in class Form1 like :
1
2
3
4
5
6
while ( true )
{
	CPM^ _oPM    = gcnew CPM(); // the class inherit from System::Windows::Forms::Form

	_oPM->ShowWindow(this);
}


in class CPM :
1
2
3
4
5
6
7
8
9
10
11
12
private: delegate System::Void ShowWindowDlg(System::Windows::Forms::IWin32Window^);

public: System::Void ShowWindow(System::Windows::Forms::IWin32Window^ owner)
{
	if ( this->InvokeRequired )
	{
		ShowWindowDlg ^dl = gcnew ShowWindowDlg(this, &CPM::ShowWindow);
		this->Invoke(dl, gcnew array<System::Object^>{ owner });
	}
	else
		this->Show( owner );
}

But break at the run time :((( please help me when call _oPM->ShowWindow(this) programm is broke.
Last edited on
Show the error messages and the stack trace. I don't know CLI, but I know .net. I may be able to help if you show error information.
i try to simulate one Messenger . when come one PM , create one form like other messenger and display the message . all of the thing work correctly but when i want to create the new form then is broke.

the message :

an unhandled exception of type 'system.invalidoperationexception' occurred in system.windows.forms.dll

additional information: cross-thread operation not valid: Control 'Form1' accessed from a thread other that the thread it was created on.
Last edited on
Topic archived. No new replies allowed.