Search code examples
c#.nettimercallrepeat

Timer Ticks 2 times in 1 interval time windows.forms.timer


This is my project design, I have mainpage and sub-pages. When i click buttons on left button menu it calls sub-forms in this mainpages panel. Since I couldn't find my problem anywhere, I wanted to summarize them for you so that we could find out what could be causing the problem.

enter image description here

this is how i call my sideforms

            panel_content.Controls.Clear();
            home.TopLevel = false;
            panel_content.Controls.Add(home);
            home.Show();

When sub-forms timer ticks its repeats 2 times in 1 interval time. How can i solve this problem. I am using .net framework timer.

My timer function:

        private void timer_PlcConnect_Tick(object sender, EventArgs e)
        {
            timer_PlcConnect.Interval = 5000;
            MessageBox.Show("is it repeat");
        }

But when i change program.cs startup form to sub form. I mean not mainpage. It works normal. Its not repeating.

How can we solve it.

My sub forms describing:

        readonly Home home = new Home();
        readonly VeriOranlari veriOranlari = new VeriOranlari();
        readonly Simulasyon simulasyon = new Simulasyon();
        readonly Kalibrasyon kalibrasyon = new Kalibrasyon();
        readonly MailAyarlari mailAyarlari = new MailAyarlari();
        readonly Raporlama raporlama = new Raporlama();
        readonly Ayarlar ayarlar = new Ayarlar();

Solution

  • I was calling side forms from mainpage and a sideform page. So which form my dublicater timer has is defined from homepage and sidepage. So I deleted sideform defines from sideform. Its solved.

    If you implement a form in your mainform, don't implement it to other side forms. For dublicating.

    readonly Anasayfa anasayfa = new Anasayfa();
    

    I hope it is of use to someone.