c# - How to close a form launched from Main() without cross-thread errors -


i have windows form application can called command line or used gui. command line options scheduling program run saved tasks, don't want gui launch if command line options used.

static void main() {     //code parse command line options     application.enablevisualstyles();     application.setcompatibletextrenderingdefault(false);     try     {         application.run(new mainform());     } }  public mainform() {     //loading data file form.     if (argumentlist.length >0)     {         //do command line-requested tasks         this.close();     }     else     {         //do gui tasks     } } 

how close mainform window without making instance of objectdisposedexception thrown? if use after

application.run(new mainform()); 

it doesn't run because form opened , nothing runs after line until form closed. i've tried

this.hide(); 

instead of

this.close(); 

but this.hide() doesn't seem in case, form still shows. know shouldn't try close form within form (cross-threading), if don't want gui form show if called command line.

you should move code main(), , avoid form entirely if don't need it.


Comments

Popular posts from this blog

android - Sent Blob results empty -

javascript - Bootstrap Popover: iOS Safari strange behaviour -