المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to present an openning screen (form) in C# application?



C# Programming
10-08-2010, 01:30 AM
Hi all
I have a rather big GUI application in C# (.NET 2.0, VS2005), which takes some time when first started (its IinitializeComponent method, along with some other setup actions I am doing takes about 4-7 seconds).

I want to present the user an 'Opening screen' that will be presented while the application gets loaded, and once it finishes, this 'Openning screen' will be vanished.

I have tried to 'show' the 'Openning screen' form before starting my applic, but it fails to be drawn completely and fails to shut off when my app finished its setup (since the main thread can't reach its close statement as it stays on the message loop of my main app).
Here is some pseudo code:

[STAThread]
static void Main(
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

OpenScreenForm op = new OpenScreenForm();
op.show();

// setup my main up
MainApp m = new mainaApp()); // time consuming operations...
Application.Run(m);

op.Close(); // this statement is never reached !!!
}
I have tried using other thread to show the openning screen, and joins him (by the main thread), so that I could make sure that the form finished its showing stuff, but this also failed (openning screen gets shown for a glimpse and hides back..)
Here is some pseudo code:

[STAThread]
static void Main(
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Thread openThread = new Thread(new ThreadStart(CreateOpenningForm));
openThread.Start();
openThread.Join();

// setup my main up
MainApp m = new mainaApp()); // time consuming operations...
op.Close(); // cross thread exception here !!!
Application.Run(m);
}
...
static void CreateOpenningForm()
{
op = new OpenScreenForm();
op.Show();
}
Does any one has any idea how to accomplish that ?
Thanks in advance