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. Threading Error

Threading Error

Scheduled Pinned Locked Moved C#
helpquestionlearning
5 Posts 3 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.
  • W Offline
    W Offline
    Wackatronic
    wrote on last edited by
    #1

    I am getting An object reference is required for the nonstatic field, method, or property 'AMPE_Server.AMPE_Service.ReadRequest()' in the following method. private static void ProcessRequest() { while ( true ) { Thread requestThread = new Thread( new ThreadStart( ReadRequest ) ); requestThread.Start(); } } which refers to the following method private void ReadRequest() { AMPE_Server.Communication.Request request = new AMPE_Server.Communication.Request() lock (this) { request = (AMPE_Server.Communication.Request) queueRequests.Dequeue(); } } What the hell have I done wrong? This learning threading is hard as hell after programming with VB for the past 10 years.
    Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!

    F S 2 Replies Last reply
    0
    • W Wackatronic

      I am getting An object reference is required for the nonstatic field, method, or property 'AMPE_Server.AMPE_Service.ReadRequest()' in the following method. private static void ProcessRequest() { while ( true ) { Thread requestThread = new Thread( new ThreadStart( ReadRequest ) ); requestThread.Start(); } } which refers to the following method private void ReadRequest() { AMPE_Server.Communication.Request request = new AMPE_Server.Communication.Request() lock (this) { request = (AMPE_Server.Communication.Request) queueRequests.Dequeue(); } } What the hell have I done wrong? This learning threading is hard as hell after programming with VB for the past 10 years.
      Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!

      F Offline
      F Offline
      flow5555
      wrote on last edited by
      #2

      private void ReadRequest() here is your problem: you need to have a static function to use threads, as they are independent proccess so write private static void ReadRequest() instead, ofcourse you have to change your code inside the function too since the method is now static. Hope that helps! flow

      S W 2 Replies Last reply
      0
      • W Wackatronic

        I am getting An object reference is required for the nonstatic field, method, or property 'AMPE_Server.AMPE_Service.ReadRequest()' in the following method. private static void ProcessRequest() { while ( true ) { Thread requestThread = new Thread( new ThreadStart( ReadRequest ) ); requestThread.Start(); } } which refers to the following method private void ReadRequest() { AMPE_Server.Communication.Request request = new AMPE_Server.Communication.Request() lock (this) { request = (AMPE_Server.Communication.Request) queueRequests.Dequeue(); } } What the hell have I done wrong? This learning threading is hard as hell after programming with VB for the past 10 years.
        Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        This isn't a threading problem and you don't need static methods to use threads. What you've done wrong is that you pass the ReadRequest method to the ThreadStart delegate without using an object. Thread requestThread = new Thread( new ThreadStart( ReadRequest ) ); As the ReadRequest method isn't static this fails. Either declare your method static or use an object. Thread requestThread = new Thread( new ThreadStart( obj.ReadRequest ) ); www.troschuetz.de

        1 Reply Last reply
        0
        • F flow5555

          private void ReadRequest() here is your problem: you need to have a static function to use threads, as they are independent proccess so write private static void ReadRequest() instead, ofcourse you have to change your code inside the function too since the method is now static. Hope that helps! flow

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          flow5555 wrote: you need to have a static function to use threads, as they are independent proccess That's not the case! www.troschuetz.de

          1 Reply Last reply
          0
          • F flow5555

            private void ReadRequest() here is your problem: you need to have a static function to use threads, as they are independent proccess so write private static void ReadRequest() instead, ofcourse you have to change your code inside the function too since the method is now static. Hope that helps! flow

            W Offline
            W Offline
            Wackatronic
            wrote on last edited by
            #5

            Thanks for the help. I redefined the method as static and had to remove the lock code. Can you explain what the lock command does? Regards, Eric C. Tomlinson
            Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!

            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