I would like to find C++ example for
creating two or more threads, each with its own window,
in a .NET and windows forms environment.
(No luck in Code Project.)
Thanks for any guidance.
Hi, I fixed this piece of code for you:
It creates two thread (both use the same thread class, of course you can
implement two different thread classes). Each time the thread procedure is
executed, it creates a window and runs Application::Run ( ... ) which runs
the message loop until the window is closed. I created a simple C++ .NET
Console project. This is the main code file:
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
#using <system.windows.forms.dll>
using namespace System;
using namespace System::Threading;
using namespace System::Windows::Forms;
__gc class FormThread {
public:
void ThreadProc ()
{
Console::WriteLine ("Hello from ThradProc");
Form *f = new Form ();
f->Show ();
Application::Run (f);
}
};
int _tmain()
{
Console::WriteLine ("Starting Thread 1");
FormThread *ft1 = new FormThread ();
Thread *t1 = new Thread (new ThreadStart (ft1, FormThread::ThreadProc));
t1->Start ();
Console::WriteLine ("Starting Thread 2");
FormThread *ft2 = new FormThread ();
Thread *t2 = new Thread (new ThreadStart (ft2, FormThread::ThreadProc));
t2->Start ();
t1->Join ();
t2->Join ();
return 0;
}
Regards
Felix Arends