O
Oleg Ogurok
Hi there,
I need to start my Windows Forms application without showing the form
initially. Then at some point, the application will be signaled to
generate and display the user interface.
I'm trying to use Application.Run() without parameters. Since this
method doesn't return I start a separate thread. The thread sleeps for
2 secs to simulate the delay and then tries to open the main form.
Somehow, with my code, the form show up for a split second and then
disappears.
Your help is greatly appreciated. I'm using .NET 1.1.
public class Program
{
public Program()
{
}
static Thread t;
static Form1 f;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
t = new Thread(new ThreadStart(StartUI));
t.Start();
Application.Run();
}
private static void StartUI()
{
Thread.Sleep(2000); // simulate delay
f = new Form1();
f.HandleCreated += new EventHandler(f_HandleCreated);
IntPtr p = f.Handle;
}
public delegate void ShowDelegate();
private static void f_HandleCreated(object sender, EventArgs e)
{
f.Invoke( new ShowDelegate(f.Show));
}
}
I need to start my Windows Forms application without showing the form
initially. Then at some point, the application will be signaled to
generate and display the user interface.
I'm trying to use Application.Run() without parameters. Since this
method doesn't return I start a separate thread. The thread sleeps for
2 secs to simulate the delay and then tries to open the main form.
Somehow, with my code, the form show up for a split second and then
disappears.
Your help is greatly appreciated. I'm using .NET 1.1.
public class Program
{
public Program()
{
}
static Thread t;
static Form1 f;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
t = new Thread(new ThreadStart(StartUI));
t.Start();
Application.Run();
}
private static void StartUI()
{
Thread.Sleep(2000); // simulate delay
f = new Form1();
f.HandleCreated += new EventHandler(f_HandleCreated);
IntPtr p = f.Handle;
}
public delegate void ShowDelegate();
private static void f_HandleCreated(object sender, EventArgs e)
{
f.Invoke( new ShowDelegate(f.Show));
}
}