problem in costum events

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • furqi
    New Member
    • Dec 2009
    • 21

    problem in costum events

    Code:
    hi there there is i have pasted a code the problem i have mentioned in the end after the code.
    
    //this is the argumentevent classi have made 
    namespace argumentsevents
    {
        delegate void myeventhandler(object source , myeventargs arg);
        class eventclass
        {
            myeventargs o = new myeventargs();
            public event myeventhandler anevent;
            public void furqan(object source, myeventargs arg)
            {
                arg.name = "faizan";
                Console.WriteLine(arg.name + "ahmed here");
                Console.WriteLine();
            }
            public void furqan1(object source, myeventargs arg)
            {
                arg.name = "furqan";
                Console.WriteLine(arg.name + "ahmed here");
            }
            public void fire()
            {
                if (anevent != null)
                {
                    anevent(this,o);//problem is here i have mentioned at the end 
                }
            }
        }
    }
    
    //here is the class inherited by "eventargs"
    
    namespace argumentsevents
    {
        class myeventargs:EventArgs 
        {
            public string name;
        }
    }
    
    
    //this is the main
    namespace argumentsevents
    {
        class Program
        {
            static void Main(string[] args)
            {
                eventclass ob = new eventclass();
                ob.anevent += ob.furqan;
                ob.anevent += ob.furqan1;
                ob.fire();
    
    
            }
        }
    }
    
    
    //now the problem 
    
    THE THING IS THAT  IN THE "ARGUMENTEVENT" CLASS  AND IN THE FIRE METHOD I HAVE USED "anevent(this,o) " I USED THIS B/C THE EVENT IS CREATED IN THE SAME CLASS WHERE THERE IS THE FIRE METHOD THATS WHY I USED EVENT.SUPPOSE I MADE THE EVENT IN "MYEVENTARGS" CLASS THEN IN THE FIRE EVENT AND INSTEAD OF PASSSSING THIS WHAT I WILL PASS "anevent(???,o) "
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    t think you should pass myeventargs.Emp ty instead of o....

    and im not able to understand what error are you facing

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3

      Comment

      Working...