DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 21:47:53 -0000,    posted on: microsoft.public.dotnet.framework.windowsforms        back       

Thread Index
  1    Oleg Ogurok
          2    AlexS LEASE
          3    Oleg Ogurok


Application.Run() without parameters, form doesn't stay open.   
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));
		}
	}
Date:Wed, 22 Aug 2007 21:47:53 -0000   Author:  

Re: Application.Run() without parameters, form doesn't stay open.   
You don;t need Application.Run in this case - just do what you need and call 
..Run method when you need to show the form using form reference. And remove 
this thread stuff - you don't need it either.

Look at the STAThread description and note that forms are designed to run on 
UI thread. If you are trying to make another thread perform as UI - I am not 
sure it will work as expected.

You can start another thread doing preparation work and wait until it is 
complete or use some event to signal back it is finished. But run the form 
on main thread to avoid surprises.

What is the real reason to deviate from recommended way?


"Oleg Ogurok"  wrote in message 
news:1187819273.221701.165260@e9g2000prf.googlegroups.com...

> 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));
> }
> }
> 
Date:Wed, 22 Aug 2007 19:14:06 -0400   Author:  

Re: Application.Run() without parameters, form doesn't stay open.   
I'm just trying to start the application silently without showing the
main form right away. Then at some point the UI will be shown.


On Aug 22, 7:14 pm, "AlexS" <salexru200...@SPAMrogers.comPLEASE>
wrote:

> You don;t need Application.Run in this case - just do what you need and call
> .Run method when you need to show the form using form reference. And remove
> this thread stuff - you don't need it either.
>
> Look at the STAThread description and note that forms are designed to run on
> UI thread. If you are trying to make another thread perform as UI - I am not
> sure it will work as expected.
>
> You can start another thread doing preparation work and wait until it is
> complete or use some event to signal back it is finished. But run the form
> on main thread to avoid surprises.
>
> What is the real reason to deviate from recommended way?
>
> "Oleg Ogurok"  wrote in message
>
> news:1187819273.221701.165260@e9g2000prf.googlegroups.com...
>
>
>
> > 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));
> > }
> > }- Hide quoted text -
>
> - Show quoted text -
Date:Thu, 23 Aug 2007 14:34:29 -0000   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us