I have a project that shows a UI when no proper command line arguments are passed. It's is a simple utility built to dynamically update a desktop wallpaper. When it's done with its update I call
this.Dispose();
but this causes an issue if command line arguments are passed. The form actually ends up getting the Dispose method call before it has been shown to the user. The result is a nasty error saying that the program failed to run properly even though it did just as I wanted.
I can respect the that that I'm not being very logical about this but I haven't a clue another way to look at a solution. Is there another way to call the Dispose() method cleanly before an application has loaded without causing an error?
Additional Info:
The above is evidentially not clear and I apologize for that. My program is started from a Program.cs file:
Application.Run(new MainForm());
In the constructor I check if command line arguments exists and if so call a routine called SilentRun. This private method checks if the arguments are valid and if so passes them to a method to commit actions called BrandSystem().
After BrandSystem() is complete, with its work, the last statement is
this.Dispose();
as there is nothing else for the application to actually do. This same method is called if no command arguments are passed and the user uses the GUI to apply the changes. Essentially once the process of updating the wallpaper is complete I want the application to terminate itself.
The reason for the command line arguments are so this utility of sorts can be added to an installation package and run silently in the background. My installation process does not have the native ability to update a wallpaper and this is a two-bird-one-stone utility for me.
The issue comes when the program runs in command line mode and calls Dispose before everything is actually loaded. I'm open to suggestions even if they prove my logic completely unsound.