Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:24:42+00:00 2026-06-11T11:24:42+00:00

I am trying to create an event that executes a function when a certain

  • 0

I am trying to create an event that executes a function when a certain amount of time has changed. The timer is done by another code, it’s supposed to call Plus(1), but will that change all timers (if I create multiple)? And this code is not actually working.

namespace @event
{
    class Program
    {
        static void Main(string[] args)
        {
            Tick tijd = new Tick();
            tijd.interval = 10;
            tijd.TijdVeranderd += new EventHandler(Uitvoeren);
            dynamic func = new Tick();

            for (int i = 0; i < 100; i++)
            {
                func.Plus(1);
            }

            Console.ReadLine();
        }

        static void Uitvoeren(object sender, EventArgs e)
        {
            Console.WriteLine("Uitgevoerd!");
        }
    }

    public class Tick
    {
        public event EventHandler TijdVeranderd;

        public int interval;

        private int tijd;

        public void Plus(int i)
        {
            tijd += 1;
        }

        public int Verander
        {
            get { return this.tijd; }
            set
            {
                this.tijd = value;

                if (tijd == interval)
                {
                    if (this.TijdVeranderd != null)
                        this.TijdVeranderd(this, new EventArgs());

                    tijd = 0;
                }
            }
        }

        public Tick() { }
    }
}

EDIT: I don’t want to use the .net timer, I want to create my own.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:24:43+00:00Added an answer on June 11, 2026 at 11:24 am

    There seem to be a couple of errors in your code:

    First of all, in Main, you are calling Plus() on a different instance of Tick than the one that you configured. Try using tijd.Plus(1) instead of func.Plus(1).

    Also, in the implementation of Plus, when you increment the private variable tijd, the code associated with the property Verander does not get executed, so no events ever fire. To quickly fix, increment Verander instead of tijd.

    namespace @event
    {
        class Program
        {
            static void Main(string[] args)
            {
                Tick tijd = new Tick();
                tijd.interval = 10;
                tijd.TijdVeranderd += new EventHandler(Uitvoeren);
    
                for (int i = 0; i < 100; i++)
                {
                    tijd.Plus(1);
                }
    
                Console.ReadLine();
            }
    
            static void Uitvoeren(object sender, EventArgs e)
            {
                Console.WriteLine("Uitgevoerd!");
            }
        }
    
        public class Tick
        {
            public event EventHandler TijdVeranderd;
    
            public int interval;
    
            private int tijd;
    
            public void Plus(int i)
            {
                Verander += 1;
            }
    
            public int Verander
            {
                get { return this.tijd; }
                set
                {
                    this.tijd = value;
    
                    if (tijd == interval)
                    {
                        if (this.TijdVeranderd != null)
                            this.TijdVeranderd(this, new EventArgs());
    
                        tijd = 0;
                    }
                }
            }
    
            public Tick() { }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a function that handles the 'keyup' event for several
Im trying to create an ajax (post) event that will populate a table in
I am trying to create a simple function that can take a parameter and
I'm trying to create a function that will execute on a click, on the
I'm trying to create a class that manages the events of a combo box
I am trying to create new Event objects to be persisted in the database
I'm trying to create an event through the Facebook Graph API and I keep
I've been trying to create a generic event. Basically it should look like this:
I have a database with event names and dates. I am trying to create
I'm trying to catch a double-click event in a TreeView's empty area to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.