Forms in their own thread.

A

andreas

Hello.

I am experimenting with C#, DirectX and .NET but it is not going very well.


The thing I am trying to do is spawn 3 threads, in each thread I create a
form and initialize a D3D-device.

What stumped me is there is no form-message-loop. The "Application.Run()"-
or "Application.DoEvents()"-methods seem more to be used for the original
thread?


The reason for 3 threads is that I have 3 displays, and I want one
thread/form on each display doing their own thing.

The original thread should simply wait until the 3 other threads have stopped
running and the die itself.

Any ideas? :)

Thanks..
 
A

Armin Zingler

andreas said:
Hello.

I am experimenting with C#, DirectX and .NET but it is not going very
well.


The thing I am trying to do is spawn 3 threads, in each thread I
create a form and initialize a D3D-device.

What stumped me is there is no form-message-loop. The
"Application.Run()"- or "Application.DoEvents()"-methods seem more to
be used for the original thread?

Why? Application.Run contains the message loop. Doesn't it work?

The reason for 3 threads is that I have 3 displays, and I want one
thread/form on each display doing their own thing.

The original thread should simply wait until the 3 other threads have
stopped running and the die itself.

Why? If the main thread doesn't have to do anything after the 3 threads have
finished, it can die immediatelly and doesn't have to wait. Otherwise, each
thread can have a Waithandle (eg ManualResetEvent) that is set when they are
done. In the main thread, you can call Waithandle.Waitall in order to
continue when all 3 threads have finished.


Armin
 
A

andreas

Armin said:
Why? Application.Run contains the message loop. Doesn't it work?
I haven't even tried.
"Application.Run()" is a black box which I have no insight on,
also there's no documentation stating it will work on forms created
within user-created threads.

Even if it does work by chance, if that behavior isn't documented
then there's a large chance my application might break in the future
due to changes in the platform.

Why? If the main thread doesn't have to do anything after the 3 threads
have finished, it can die immediatelly and doesn't have to wait.
Otherwise, each thread can have a Waithandle (eg ManualResetEvent) that
is set when they are done. In the main thread, you can call
Waithandle.Waitall in order to continue when all 3 threads have finished.
"Waithandle.Waitall" is what I will use. That is no problem.
The problem is to have each thread/form having their own message loop. :)
 
A

Armin Zingler

andreas said:
"Waithandle.Waitall" is what I will use. That is no problem.
The problem is to have each thread/form having their own message
loop. :)

Application.Run is the way to go.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top