StrataFrame Forum

Running an exe automatically - form invisible

http://forum.strataframe.net/Topic27007.aspx

By Ger Cannoll - 4/27/2010

I have a small app(not strataframe, plain vanilla c#) which does some updating and consists of just one form with a few buttons. This exe is also set up to run automatically, which is controlled by means of a parameter passed in e.g. MyExe "1". If I just run a MyExe without the parameter, I want the form to appear so I can click a few buttons. if I run MyExe with the parameter, i just want the form to run stuff on one of the buttons. I have this all working. My problem is that , when I run in unattended mode, the form itself does not display on the screen. The form runs ok but I cant see what its doing. I know when the form is up and running there is no benefit to be able to 'see' the form (as it will be running in unattended mode)  but at this stage I would like to see the form and its associated messages. If I was doing this in VFP, I would have a MyForm.Show.

Is there something similar I need to do , to get visibility of the form ?

By Edhy Rijo - 4/27/2010

Hi Gerard,

Can you post the code you are using to show the form? or better yet, small sample application with desired functionality.

By Bill Cunnien - 4/27/2010

Perhaps a slightly different approach would be to utilize the NotifyIcon on the main form. Just drag one on the form from the Common Controls section. Use your startup parameter to start the form minimized or maximized. On the form load you could check to see which state it is in, then run the appropriate methods. Lots of options available with this little object.



Hope that helps!

Bill
By Greg McGuffey - 5/18/2010

Gerard,



I've created a couple of sample apps to demonstrate a couple of ways to do this.



The first way, via the UnattendedModeSample, shows how to have your exe be opened either with a normal UI or to just automatically run a process. The process opens a status form and updates it no matter how it is called.



The second method is more robust, decoupling the process entirely from any UI. The other three projects demonstrate this. The SampleProcess project has a class that runs a process. When the process runs, it raises an event ProcessStepCompleted that consumers can handle to display messages from the process. The ProcessWinformUI will display the process messages in a textbox on the form, while the ProcessConsoleUI displays the progress to the command window.



The second method allows for completely unattended running, use in batch files etc. because the process runs completely with without user interface.


By Russell Scott Brown - 5/18/2010

Thanks for the examples!
By Greg McGuffey - 5/18/2010

My pleasure!
By Ger Cannoll - 6/2/2010

Greg, thanks for samples.

I have been off on a tangent doing other things but hopefully will get to look at these in the next while.

Regards,

Gerard