Create run form from non-graphical class

  • Thread starter Thread starter chrizl
  • Start date Start date
C

chrizl

Hi,

I am trying to create a form from an non-graphical class. This however
does not seem to work.

I can create the form just fine, and I can call functions in the form
i.e. show a messagebox. But the Form itself is not showing. When I call
Application.Run on the Form the rest of my non-graphical code is not
executed.

Is it possible to do this or do I need to have a Form as the first
class?

Thanks,
Chris Langstraat
 
Can you post a small sample of what you are trying... I for one don't get
what you describe (other might though so give it some time)

Cheers
Daniel
 
So are you saying you have this:

DoStuff();
Application.Run(new MyForm);
DoMoreStuff();

And DoMoreStuff is never occurring?

If so, that's expected behavior. Application.Run is a blocking call. It
starts a message pump and won't return until the Form is closed.

ApplicationEx.Run in the SDF gets past this with a non-Form ctor.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Thanks for your replies.

I know that Application.Run blocks everthing so I abandoned (?) that
pretty fast.

What I have tried is this:
static void Main(string[] args)
{
Core core = new Core();
Thread coreThread = new Thread(new ThreadStart(core.init));
}
Core is the class that handles all other classes.
public void init()
{
this.gui = new GUI();
this.gui.init();
//Thread guiThread = new Thread(new ThreadStart(this.gui.init));
}
I have tried putting the gui.init() in a seperate tread, but that all
doesn't seem to work.
Is it even possible to execute a Form that behaves normal from a
non-graphical class because I`m beginning to think that you must use a
Form as the "core"

Thanks
Chris
 
You are going outside the norm, against the recommendations and probably
into unsupported land...

Tell us what it is you are trying to achieve? If your app is going to have
at least one form, make that form the startup and form there launch other
forms/classes/code...

For starting up you should use Application.Run or ApplicationEx.Run and
that's pretty much it...

If you insist on experimenting with other approaches, you must keep the rule
in mind: All UI elements (forms, controls etc) must be
created/accessed/touched by the same thread.

Cheers
Daniel
 
Back
Top