Threading

  • Thread starter Thread starter John Baro
  • Start date Start date
J

John Baro

How can I create a form on a separate thread?
FormA running on ThreadA
FormB running on ThreadB

TIA
JB
 
John Baro said:
How can I create a form on a separate thread?
FormA running on ThreadA
FormB running on ThreadB

I believe you can call Application.Run from a new thread - so you'd
call Application.Run(new FormA()) on ThreadA, and
Application.Run(new FormB()) on ThreadB.

Can I ask why you want to do that though?
 
Hi Jon
Thanks for the reply.
I will try App.Run
I want to create a form that will show a progress bar (either traditional
progress or simply a moving gradient) that needs to run on a separate thread
to enable proper UI updating.
The progress bar can be either on a contained timer or updated using
Control.Invoke from the main thread.

After looking at MSDN I cannot see how I can use app.run to run a new form
on a specific thread.

This is the desired scenario
Form1 needs to do whole lot of processing
Form1 creates new progressform on separate thread.
Form1 updates progressform with form1's progress

(Form1 needs to retain a reference to progressform obviously)

Cheers
JB
 
Wouldn't it be better to put the heavy processing on it's own thread and
keep a single Form for all the GUI stuff? Whenever a value changes or at
certain intervals, notify Form1 in some way and have Form1 update the
progress.

Happy coding!
Morten Wennevik [C# MVP]
 
John Baro said:
I will try App.Run
I want to create a form that will show a progress bar (either traditional
progress or simply a moving gradient) that needs to run on a separate thread
to enable proper UI updating.

I don't see why.
The progress bar can be either on a contained timer or updated using
Control.Invoke from the main thread.

Unless you're using System.Windows.Forms.Timer, don't do anything other
than update the UI on the UI thread. If you've got work going on which
you need to report the progress of, you should definitely run that work
in a different thread, and use Control.Invoke to update the progress
bar. There's no reason why you should have two UI threads - just one
worker thread and one UI thread.
After looking at MSDN I cannot see how I can use app.run to run a new form
on a specific thread.

You just run it from a different thread - but I still don't think you
really need to.
 
Morten Wennevik said:
Wouldn't it be better to put the heavy processing on it's own thread and
keep a single Form for all the GUI stuff? Whenever a value changes or at
certain intervals, notify Form1 in some way and have Form1 update the
progress.

I don't see any reason to restrict the design to a single form (and I'd
never call a class Form1!) but restricting all UI operations to a
single *thread* seems reasonable.
 
I don't see any reason to restrict the design to a single form (and I'd
never call a class Form1!) but restricting all UI operations to a
single *thread* seems reasonable.

Ah, he called it FormA, not Form1, my mistake :)
And I had a feeling he was trying to show information in two separate
forms that would normally be put in a single form. But by all means,
simple applications have lots of forms :)


Happy coding!
Morten Wennevik [C# MVP]
 
Hi Jon
The actual processing going on in the first form is the loading of the
controls etc.. which I dont really want to separate onto their own thread.
I might have to eventually but..
I want to create a generic progress form that I can create whenever
necessary to show progress from another form.
It cannot be too hard to move a form to a new thread.
I will post the solution here after I find it.

Cheers
JB
 
Back
Top