In my application, I have it call a startup method in my MainForm class called OnStart, which is defined as such:
public void OnStart()
{
//code
}
When I call it from the Main method, it doesn’t run. What am I doing wrong?
(Oh, and the same thing as with the OnStop method.)
Here is my Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Logger
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm mainForm = new MainForm();
Application.Run(mainForm);
AppDomain.CurrentDomain.ProcessExit += new EventHandler (mainForm.OnStop);
mainForm.OnStart();
}
}
}
Application.Runwill hang until your form closes so you’ll need to callOnStartbefore it andOnStopafter.