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. Accessing control from seperate class

Accessing control from seperate class

Scheduled Pinned Locked Moved C#
question
6 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.
  • O Offline
    O Offline
    oceanexplorer
    wrote on last edited by
    #1

    Hi, I need to call an invoke method on a list box called lstLogger, e.g. lstLogger.BeginInvoke(delegate, object) However that would be fine if I was in the same class as the lstLogger, but I'm in a seperate class. How can I access lstLogger in order to call the BeginInvoke method? Regards Paul

    L 1 Reply Last reply
    0
    • O oceanexplorer

      Hi, I need to call an invoke method on a list box called lstLogger, e.g. lstLogger.BeginInvoke(delegate, object) However that would be fine if I was in the same class as the lstLogger, but I'm in a seperate class. How can I access lstLogger in order to call the BeginInvoke method? Regards Paul

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

      Paul, I hate to say this but your question makes you sound like this is your first day programming. How you access object A from object B is that object B must have a reference to object A. Now there are many, many ways for this to happen so I don't know what you want us to tell you.

      O 1 Reply Last reply
      0
      • L led mike

        Paul, I hate to say this but your question makes you sound like this is your first day programming. How you access object A from object B is that object B must have a reference to object A. Now there are many, many ways for this to happen so I don't know what you want us to tell you.

        O Offline
        O Offline
        oceanexplorer
        wrote on last edited by
        #3

        Yep I know I'm having a dumb blonde moment! To be honest I know about accesing controls from other classes etc. But my difficulty with this one is I am dealing with threading, I have a UI that runs on one thread, when a button is pressed, it creates a new thread and goes of and executes another (labour intensive task), within the running task I want to make callbacks to the UI to update a listbox with messages. I have setup the delegates fine but my trouble is in accessing the listbox control to call the begininvoke method e.g. lstLogger.BeginInvoke(delegate, object) To call this from the other class I would need to create a new instance of the Logger class which contains the listbox lstLogger, but I don't want to do this, I want to invoke a method on a seperate thread that is already running. It's driving me nuts, all the examples I can find do it from within the same class, which is easy to set up as I have access to the lstLogger control. Hope that explains a bit more and doens't make me sound so dumb! Regards Paul

        L 1 Reply Last reply
        0
        • O oceanexplorer

          Yep I know I'm having a dumb blonde moment! To be honest I know about accesing controls from other classes etc. But my difficulty with this one is I am dealing with threading, I have a UI that runs on one thread, when a button is pressed, it creates a new thread and goes of and executes another (labour intensive task), within the running task I want to make callbacks to the UI to update a listbox with messages. I have setup the delegates fine but my trouble is in accessing the listbox control to call the begininvoke method e.g. lstLogger.BeginInvoke(delegate, object) To call this from the other class I would need to create a new instance of the Logger class which contains the listbox lstLogger, but I don't want to do this, I want to invoke a method on a seperate thread that is already running. It's driving me nuts, all the examples I can find do it from within the same class, which is easy to set up as I have access to the lstLogger control. Hope that explains a bit more and doens't make me sound so dumb! Regards Paul

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

          oceanexplorer wrote:

          But my difficulty with this one is I am dealing with threading

          Slow down and relax. The threading issue is completely separate from the object access issue. You actually seem to be aware of that but perhaps your frustration is not allowing you to realize it.

          oceanexplorer wrote:

          To be honest I know about accesing controls from other classes etc.

          Then start there. Don't think about the thread issue and solve the access problem first. Once you have access to the object then go back to solving the thread issue. #1 Get access to the object I need. #2 Now I am in another thread so I need to Invoke the object rather than just call it's method. Also take a look at this[^] and see if it helps.

          O 1 Reply Last reply
          0
          • L led mike

            oceanexplorer wrote:

            But my difficulty with this one is I am dealing with threading

            Slow down and relax. The threading issue is completely separate from the object access issue. You actually seem to be aware of that but perhaps your frustration is not allowing you to realize it.

            oceanexplorer wrote:

            To be honest I know about accesing controls from other classes etc.

            Then start there. Don't think about the thread issue and solve the access problem first. Once you have access to the object then go back to solving the thread issue. #1 Get access to the object I need. #2 Now I am in another thread so I need to Invoke the object rather than just call it's method. Also take a look at this[^] and see if it helps.

            O Offline
            O Offline
            oceanexplorer
            wrote on last edited by
            #5

            Thanks Mike, It's friday, I'm bored of thinking and want to go home!! In order to gain access to the object, I tired making it public rather than private but I still cannot see it, public static allows me to see it but then that causes hassle in construction and it won't build. I would normally create public property accessors but I need access to the object in order to invoke methods. Any ideas? Thanks again Paul

            L 1 Reply Last reply
            0
            • O oceanexplorer

              Thanks Mike, It's friday, I'm bored of thinking and want to go home!! In order to gain access to the object, I tired making it public rather than private but I still cannot see it, public static allows me to see it but then that causes hassle in construction and it won't build. I would normally create public property accessors but I need access to the object in order to invoke methods. Any ideas? Thanks again Paul

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

              oceanexplorer wrote:

              It's friday, I'm bored of thinking and want to go home!!

              oceanexplorer wrote:

              Any ideas?

              Sounds like you need to go home and come back to this with a fresh mind on Monday. If you put any efforts in over the weekend I would suggest limiting that to reading some design material, perhaps patterns or something. Nothing directly related to your project.

              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