Jump to content

Run a query every 2 seconds.

- - - - -

  • Please log in to reply
No replies to this topic

#1
AWS

AWS

    Administrator

  • Administrators
  • 54139 posts
  • LocationJoliet, IL U.S.A.

Dear All,

            I have an application where I would like to run a query every seconds based on the current time. So I started a thread for that but I got stuck at the onstart and onstop method. I would like to check too if thread is still running then do not let next one run till the previous is done.

Error 1 'win3.Form1.onstart(string[])': no suitable method found to override C:Documents and SettingsnsMy DocumentsVisual Studio 2010Projectswin3win3Form1.cs 25 33 win3

Error 2 'win3.Form1.onstop()': no suitable method found to override C:Documents and SettingsnsMy DocumentsVisual Studio 2010Projectswin3win3Form1.cs 31 33 win3

Below is my codes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.IO;
using System.Threading;
namespace win3
{
    public partial class Form1 : Form
    {
        private Thread doWorkThread;

        private bool existThread = false;
        
        public Form1()
        {
            InitializeComponent();
            this.doWorkThread = new Thread(new ThreadStart(DoWork));
        }
        protected override void onstart(string[] args)
        {

            this.doWorkThread.Start(); // Start The Thread
        }

        protected override void onstop()
        {
            this.existThread = true;
        }
        private void DoWork()
        {
            MessageBox.Show("TEST");
            while (true)
            {

                if (this.existThread) 
                    return;
                //to run my query every 2 seconds
                Thread.Sleep(TimeSpan.FromSeconds(20));
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
}



View the full article




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users