Reputation: 1919
In my client.cs, I would like to open up a form application. So I wrote:
SS.Program.Main(); // open up the window
SS.Form1 f = new Form1(); // create instance
f.updateCell('A', 1, "hi"); // update a cell in the window that I opened up
However, the code is stuck at SS.Program.Main(); and does not proceed to the next lines. How do I make the code run the next lines? It seems like the SS.Program.Main() is an infinite loop. But I need that in order to continue running the form.
SS.Program.Main()
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Start an application context and run one form inside it
DemoApplicationContext appContext = DemoApplicationContext.getAppContext();
appContext.RunForm(new Form1());
Application.Run(appContext);
}
}
Upvotes: 0
Views: 563
Reputation: 62093
You close the window ;)
No, seriously.
Application.Run tells the thread to now act as the message pump for the UI until the UI has been closed totally.
So the code behind only gets executed when the UI shuts down.
In your particular case, all that code should be before the application.Run and your main form should likely replace the Form1 that was pregenerated and is now totally useless.
Upvotes: 3