It is expected.
> Application.Run(new Form1()) ;
This will start the windows message loop on the current thread (not in a new
thread).
> // a Thread.sleep() call sits here
This will never be called before the message loop exits the loop and
returns. The WinForm must first exit.
Only "one" thread is running.
What do you want the app to do? How do you want it to exit? Maybe we can
come up with an example.
Regards,
Lars-Inge T?nnessen
BGU - 17 Sep 2004 04:50 GMT
Hi, thanks. The goal is simple:
- User launches my program
- It displays some information for 30 seconds
- It exits automatically
If you can suggest a way to make my VJ#/WinForms program terminate without
being prompted to do so by the user, that would help.
Peace,
Gordon
> It is expected.
>
[quoted text clipped - 15 lines]
> Regards,
> Lars-Inge T?nnessen
Lars-Inge T?nnessen [VJ# MVP] - 17 Sep 2004 13:54 GMT
I would suggest a timer. Here is an example I have written for you. This is
a J# WinForms app that will run for 5 seconds and then shutdown.
I'm using a timer (private System.Threading.Timer) to start a method
(private void TimerShutdown( Object arg )) after 5 seconds. As you can see
in the example, I'm creating the timer instance in the constructor.
import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Data.*;
/**
* Summary description for Form1.
*/
public class Form1 extends System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
// Timer
private System.Threading.Timer timer = null;
public Form1()
{
InitializeComponent();
// Maka the Timer
this.timer = new System.Threading.Timer(
new System.Threading.TimerCallback(TimerShutdown), // Method to be called
null,
5000, // 5 sec
0 );
}
// The timer method
private void TimerShutdown( Object arg )
{
System.exit(0);
}
protected void Dispose(boolean disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
super.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.set_AutoScaleBaseSize(new System.Drawing.Size(5, 13));
this.set_ClientSize(new System.Drawing.Size(292, 266));
this.set_Name("Form1");
this.set_Text("Form1");
this.ResumeLayout(false);
}
/** @attribute System.STAThread() */
public static void main(String[] args)
{
Application.Run(new Form1());
}
}
Regards,
Lars-Inge T?nnessen