tags:

views:

32

answers:

1

Hi

I want to send some kind of hearbeat at every configured time interval. I want to use dispatcher timer to send it.

Main()
{
  create dispatcher timer;

}

void dispacthertimertick()
{
 // send heartbeat
}

How do i keep the main thread alive?

Regards Raju

A: 

The best place to put it is in your App.xaml.cs. Application in WPF is responsible for setting the message loop so you should not really worry about it. If your App.xaml has a build action property of ApplicationDefinition (which is the default), it will emit this start up code (which you can see using Reflector):

[STAThread, DebuggerNonUserCode]
public static void Main()
{
  App app = new App();
  app.InitializeComponent();
  app.Run();
}

You need to use OnStartup:

protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        // setup your timer here
    }

Console.Read() is really a hack and unnecessary since there could be no console, as is the case in Windows forms.

Aliostad