Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Working with events

Working with events

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stonee74
    wrote on last edited by
    #1

    Hi there, I would like to notify my app if a socketconnection is broken. I tried to use a self created event, with wich i want to notify an upper class in such a case. The problem is i receive a unhandled exception of type 'System.MissingMethodException'... Why? What Am i doing wrong and what means this error? Thanks a lot, stonee internal delegate void ConnectionHandler(SocketException se); ............ public class Control { internal event ConnectionHandler OnConnectionProblem; ................ public Control() { OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem); .................... catch(SocketException se) { / MessageBox.Show (se.Message ); try { OnConnectionProblem(se); } catch(MissingMethodException mme) { MessageBox.Show(mme.Message+"::"+mme.InnerException); }

    J 1 Reply Last reply
    0
    • S stonee74

      Hi there, I would like to notify my app if a socketconnection is broken. I tried to use a self created event, with wich i want to notify an upper class in such a case. The problem is i receive a unhandled exception of type 'System.MissingMethodException'... Why? What Am i doing wrong and what means this error? Thanks a lot, stonee internal delegate void ConnectionHandler(SocketException se); ............ public class Control { internal event ConnectionHandler OnConnectionProblem; ................ public Control() { OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem); .................... catch(SocketException se) { / MessageBox.Show (se.Message ); try { OnConnectionProblem(se); } catch(MissingMethodException mme) { MessageBox.Show(mme.Message+"::"+mme.InnerException); }

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      Here's the problem: stonee74 wrote: OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem); There's no method ESControl_OnConnectionProblem Here's how I would do it:

      // this defines the event delegate
      public delegate void ConnectionHandler(object sender, SocketException se);
      // this keeps all event arguments
      public class ConnectionProblemEventArgs
      {
      private SocketException m_SocketException;
      public ConnectionProblemEventArgs(SocketException se)
      {
      SocketException = se;
      }
      public SocketException SocketException
      {
      get
      { return m_SocketException; }
      }
      }
      public class EsControl
      {
      // here's the event definition
      public event ConnectionHandler ConnectionProblem;

      // this raises the event
      public virtual void OnConnectionProblem(SocketException se)
      {
      	if (ConnectionProblem != null)
      		ConnectionProblem (this, new ConnectionProblemEventArgs (se));
      }
      
      private DoSomethingWithSocket()
      {
      	try
      	{
      		...
      	}
      	catch(SocketException se)
      	{
      		// raise the event
      		OnConnectionProblem (se);
      	}
      }
      

      }
      public class EventListner
      {
      public EventListner(EsControl esControl)
      {
      // subscribe to event here
      EsControl.ConnectionProblem += new ConnectionHandler (ESControl_ConnectionProblem);
      }

      private void ESControl\_ConnectionProblem(object sender, ConnectionProblemEventArgs e)
      {
      	// Handle event here
      }
      

      }

      α.γεεκ

      Fortune passes everywhere.
      Duke Leto Atreides

      S 1 Reply Last reply
      0
      • J Jim Stewart

        Here's the problem: stonee74 wrote: OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem); There's no method ESControl_OnConnectionProblem Here's how I would do it:

        // this defines the event delegate
        public delegate void ConnectionHandler(object sender, SocketException se);
        // this keeps all event arguments
        public class ConnectionProblemEventArgs
        {
        private SocketException m_SocketException;
        public ConnectionProblemEventArgs(SocketException se)
        {
        SocketException = se;
        }
        public SocketException SocketException
        {
        get
        { return m_SocketException; }
        }
        }
        public class EsControl
        {
        // here's the event definition
        public event ConnectionHandler ConnectionProblem;

        // this raises the event
        public virtual void OnConnectionProblem(SocketException se)
        {
        	if (ConnectionProblem != null)
        		ConnectionProblem (this, new ConnectionProblemEventArgs (se));
        }
        
        private DoSomethingWithSocket()
        {
        	try
        	{
        		...
        	}
        	catch(SocketException se)
        	{
        		// raise the event
        		OnConnectionProblem (se);
        	}
        }
        

        }
        public class EventListner
        {
        public EventListner(EsControl esControl)
        {
        // subscribe to event here
        EsControl.ConnectionProblem += new ConnectionHandler (ESControl_ConnectionProblem);
        }

        private void ESControl\_ConnectionProblem(object sender, ConnectionProblemEventArgs e)
        {
        	// Handle event here
        }
        

        }

        α.γεεκ

        Fortune passes everywhere.
        Duke Leto Atreides

        S Offline
        S Offline
        stonee74
        wrote on last edited by
        #3

        thanks, I'm sure this will work. I have in my original class a method definition. I still cannot understand the errormessage.. private void ESControl_OnConnectionProblem() { } thanks for all inputs. regards, stonee

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups