Non interactive "form"?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi all,

Is there a "standard" way to structure a small windows form such that it can
run non-interactively with an appropriate command line switch?

E.g, if I run the form normally I get the form's UI, but if I run it with /q
(or whatever), it runs non-interactively (perhaps logging to the event log).
I did try parsing the command line in Main(), but of course Main is static
and it's not possible therefore to use some field or method elsewhere in the
form based on what happens in Main(). I also tried parsing the command line
in the form's constructor but I noticed that once the code has got this far,
the form appears even if I skip InitializeComponent().

I guess that there's a standard way to do this?

TIA
Mark
 
Mark said:
Is there a "standard" way to structure a small windows form such that it can
run non-interactively with an appropriate command line switch?

E.g, if I run the form normally I get the form's UI, but if I run it with /q
(or whatever), it runs non-interactively (perhaps logging to the event log).
I did try parsing the command line in Main(), but of course Main is static
and it's not possible therefore to use some field or method elsewhere in the
form based on what happens in Main(). I also tried parsing the command line
in the form's constructor but I noticed that once the code has got this far,
the form appears even if I skip InitializeComponent().

I guess that there's a standard way to do this?


Keep all your business logic (or whatever) separate from your GUI code.
If you get an appropriate command line, run the code non-interactively,
otherwise start up the GUI which controls the business logic. Sort of:

Main method
/ \
/ \
GUI Non-GUI
\ /
\ /
Core logic

That suggests (to me, at least) that your form shouldn't be the class
containing the Main method - it might even be a separate class on its
own, solely for startup purposes.
 
[snip]
Keep all your business logic (or whatever) separate from your GUI code.
If you get an appropriate command line, run the code non-interactively,
otherwise start up the GUI which controls the business logic. Sort of:

Main method
/ \
/ \
GUI Non-GUI
\ /
\ /
Core logic

That suggests (to me, at least) that your form shouldn't be the class
containing the Main method - it might even be a separate class on its
own, solely for startup purposes.

Ah! Yes, this makes sense. In fact the non-gui code _is_ the core logic, so
what I have is:

Main method
/ \
Gui |
| |
\ /
Core logic

So, as you say, I've simply created a separate class for each of the three
sections above and it works a treat. Thanks very much for your help.

Mark
 
Back
Top