Problem with C # Timer

Hello, I am currently having a timer problem in the program that I am developing. The timer starts and calls methods that receive Windows management information from a remote PC after a specified period of time and repeat this.

The first time the timer calls all this well, however the second time, after the timer has completed its task, it breaks through it again, and the third time it starts it 3 times, etc. The for loop in the code below works fine with the timer itself.

This way, any help will be charged, and if you need more information, please let me know.

Below is my code:

private void tmrStore_Tick(object sender, EventArgs e)
    {
        string ipAdd;
        ipAdd = "127.0.0.1";
        List<TblServer> Server;

        WMIInfo localDB = new WMIInfo("Data Source=|DataDirectory|\\WMIInfo.sdf");

        Server = localDB.TblServer.ToList();

        if (Server.Count == 0)
        {

        }
        else
        {
            for (int counter = 0; counter < Server.Count; counter++)
            {
                CPUStore cpu = new CPUStore();
                cpu.Store(Server[counter].IpAdd);

                HDDStore hdd = new HDDStore();
                hdd.Store(Server[counter].IpAdd);

                MemStore mem = new MemStore();
                mem.Store(Server[counter].IpAdd);

                //delete items over 24 hours old 
            }
        }
+3
source share
3 answers

, , , , doh!

, , , lol

-1

, :

tmrStore.Enabled = false;
try{
    // do stuff
}finally{
    tmrStore.Enabled = true;
}

, , , Timer.Ticks, .

, .

+3

, Timer.Tick , . "tmrStore.Tick + =", , .

0

Source: https://habr.com/ru/post/1712802/


All Articles