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. FileSystemEventHandler arg type

FileSystemEventHandler arg type

Scheduled Pinned Locked Moved C#
tutorialquestioncsharpc++
5 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.
  • N Offline
    N Offline
    Not Knuth
    wrote on last edited by
    #1

    I need to create an instance of FileSystemEventHandler inside a function, using a parameter passed into that function. FileSystemEventHandler takes an Object type that represents the method called by the FileSystemEventHandler delegate. This would be easy with C++ since I can use a pointer to a method, but I'm lost in how to do it in C#. :confused: How can I pass this into my function so I can create the instance? For example: Where OnChanged is the method for the delegate to call.

    private void CallingFunc()
    {
    MyFunc(OnChanged); // ? How to prepresent this method?
    }

    // ? what type do I use as the input parameter here?
    private void MyFunc(SomeType theMethodToCall)
    {
    FileSystemEventHandler(theMethodToCall);
    }

    TIA :)

    L 1 Reply Last reply
    0
    • N Not Knuth

      I need to create an instance of FileSystemEventHandler inside a function, using a parameter passed into that function. FileSystemEventHandler takes an Object type that represents the method called by the FileSystemEventHandler delegate. This would be easy with C++ since I can use a pointer to a method, but I'm lost in how to do it in C#. :confused: How can I pass this into my function so I can create the instance? For example: Where OnChanged is the method for the delegate to call.

      private void CallingFunc()
      {
      MyFunc(OnChanged); // ? How to prepresent this method?
      }

      // ? what type do I use as the input parameter here?
      private void MyFunc(SomeType theMethodToCall)
      {
      FileSystemEventHandler(theMethodToCall);
      }

      TIA :)

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Not Knuth wrote:

      // ? what type do I use as the input parameter here?

      I can't tell what you are trying to do but maybe you could use FileSystemEventHandler as the parameter type. Also just guessing here but you may have a design issue. Can't really tell based on your post because:

      Not Knuth wrote:

      private void MyFunc(SomeType theMethodToCall) { FileSystemEventHandler(theMethodToCall); }

      that just doesn't make any sense because you would be creating a handler that is not registered with any event so it's pointless.

      led mike

      N 1 Reply Last reply
      0
      • L led mike

        Not Knuth wrote:

        // ? what type do I use as the input parameter here?

        I can't tell what you are trying to do but maybe you could use FileSystemEventHandler as the parameter type. Also just guessing here but you may have a design issue. Can't really tell based on your post because:

        Not Knuth wrote:

        private void MyFunc(SomeType theMethodToCall) { FileSystemEventHandler(theMethodToCall); }

        that just doesn't make any sense because you would be creating a handler that is not registered with any event so it's pointless.

        led mike

        N Offline
        N Offline
        Not Knuth
        wrote on last edited by
        #3

        I was trying to keep the code sample simple. Maybe too simple! This is part of a class that wraps FileSystemWatcher to provide some other functionality that is needed. The situation with the arg for this method arises because I need to be able to set the method(s) to be called by the delegates for the instance of FileSystemWatcher that is wrapped in the class. Thanks for trying to make sense of my sample code!

        L 1 Reply Last reply
        0
        • N Not Knuth

          I was trying to keep the code sample simple. Maybe too simple! This is part of a class that wraps FileSystemWatcher to provide some other functionality that is needed. The situation with the arg for this method arises because I need to be able to set the method(s) to be called by the delegates for the instance of FileSystemWatcher that is wrapped in the class. Thanks for trying to make sense of my sample code!

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Not Knuth wrote:

          This is part of a class that wraps FileSystemWatcher

          so then that should work yes?

          private void MyFunc(FileSystemEventHandler handler)
          {
              fileSystemWatcher1.Changed += handler;
          }

          led mike

          N 1 Reply Last reply
          0
          • L led mike

            Not Knuth wrote:

            This is part of a class that wraps FileSystemWatcher

            so then that should work yes?

            private void MyFunc(FileSystemEventHandler handler)
            {
                fileSystemWatcher1.Changed += handler;
            }

            led mike

            N Offline
            N Offline
            Not Knuth
            wrote on last edited by
            #5

            Yes. It works perfectly. And it's very obvious... now that you point it out! :-O led Mike comes through again! Thank you.

            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