-3

how to use windows service in windows form application? I am having the database table , consists of Gold, silver,etc.. Prices. These can be displayed in Windows Form.

I want to Update those things periodically in Windows Form(example : for each 10 mins, need to update). Is there possible way available?

Vino
  • 99
  • 3
  • 11

2 Answers2

2

You can use Timer to periodically update the database

Timer timer = new Timer();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
    timer.Interval = (10) * (1);             // Timer will tick evert 10 seconds
    timer.Enabled = true;                       // Enable the timer
    timer.Start();

void timer_Tick(object sender, EventArgs e)
{
    //Put your technique for updating database here
}

You can invoke service like this

using System.ServiceProcess;
ServiceController sc = new ServiceController("My service name");
if (sc.Status == ServiceControllerStatus.Stopped)
{
   sc.Start();
}
Jibran Khan
  • 3,236
  • 4
  • 37
  • 50
0

Use the Forms timer.

If the update takes more than a few seconds, do the work in a background worker. If you use the background worker, I'd wrap it in code to prevent multiple simultaneous executions.

Brad Bruce
  • 7,638
  • 3
  • 39
  • 60