Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
namespace wildert
{
    public class Metronome
    {
        public event TickHandler Tick;
        public EventArgs e = null;
        public delegate void TickHandler(Metronome m, EventArgs e);
        public void Start()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(3000);
                if (Tick != null)
                {
                    Tick(this, e);
                }
            }
        }
    }
        public class Listener
        {
            public void Subscribe(Metronome m)
            {
            m.Tick += new Metronome.TickHandler(HeardIt);//I am getting error here
            }
            private void HeardIt(Metronome m, EventArgs e)
            {
                System.Console.WriteLine("HEARD IT");
            }

        }
    class Test
    {
        static void Main()
        {
            Metronome m = new Metronome();
            Listener l = new Listener();
            l.Subscribe(m);
            m.Start();
        }
    }
}

Erroe is:Error 1 Cannot implicitly convert type 'Event_Delegates.Metronome.TickHandler' to 'System.EventHandler'

Can any one help me. Y i am getting this error ,i given the full code snippet please above....
Posted
Updated 25-Jul-12 19:48pm
v3

1 solution

You are confused. This does not work. You can't change the definition of the tick event on a timer. How does the timer know what to pass through ? What you need to do, is hook up a normal tick event, then fire an event of your type, if that's what you want. You are creating a new type of event, and asking an existing class to know what it is, and it cannot know.
 
Share this answer
 
Comments
mahesh.b.p.c 26-Jul-12 2:42am    
Hi Christian Graus

Please verify below link....
http://www.codeproject.com/Articles/11541/The-Simplest-C-Events-Example-Imaginable?msg=4320885#xx4320885xx
Christian Graus 26-Jul-12 18:12pm    
Yes, you changed the code and broke it. By making 'time of tick' derive from eventargs, his code conforms to the signature of a tick, and yours does not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900