how to run a winform from console application?

The easiest option is to start a windows forms project, then change the output-type to Console Application. Alternatively, just add a reference to System.Windows.Forms.dll, and start coding: using System.Windows.Forms; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form()); // or whatever } The important bit is the [STAThread] on your Main() method, required for full COM … Read more

Hide console window from Process.Start C#

I had a similar issue when attempting to start a process without showing the console window. I tested with several different combinations of property values until I found one that exhibited the behavior I wanted. Here is a page detailing why the UseShellExecute property must be set to false. http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx Under Remarks section on page: … Read more

.NET console application exit event

You can use the ProcessExit event of the AppDomain: class Program { static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); // do some work } static void CurrentDomain_ProcessExit(object sender, EventArgs e) { Console.WriteLine(“exit”); } } Update Here is a full example program with an empty “message pump” running on a separate thread, that allows … Read more

How can I clear console

For pure C++ You can’t. C++ doesn’t even have the concept of a console. The program could be printing to a printer, outputting straight to a file, or being redirected to the input of another program for all it cares. Even if you could clear the console in C++, it would make those cases significantly … Read more

Could not load file or assembly … An attempt was made to load a program with an incorrect format (System.BadImageFormatException)

I am pretty sure you’re having a 32-bit / 64-bit conflict. It sounds like your main project might be set to 32-bit while the class its referencing is set to 64-bit. Try looking at this SO question and this one too. Between the two of them, you should be able to figure out your problem.