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. The name 'Beeper' does not exist in the current context

The name 'Beeper' does not exist in the current context

Scheduled Pinned Locked Moved C#
12 Posts 4 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.
  • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

    Beeper is a member function of Singer (the class)... Calling it like Beeper alone will only work when you are in the context of Singer (from other members for instance). If you are out of that context you have to tell the compiler the new/actual context... in your case cacophony... So the code should be like this:

    new ThreadStart(cacophony.Beeper(...));

    Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

    M Offline
    M Offline
    Member 12244972
    wrote on last edited by
    #3

    Ok, now the error is:

    Method name expected.

    Any ideas?

    Kornfeld Eliyahu PeterK 1 Reply Last reply
    0
    • M Member 12244972

      Ok, now the error is:

      Method name expected.

      Any ideas?

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #4

      For that all you have to do is to RTFM... ThreadStart Delegate (System.Threading)[^]

      Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      M 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        For that all you have to do is to RTFM... ThreadStart Delegate (System.Threading)[^]

        Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

        M Offline
        M Offline
        Member 12244972
        wrote on last edited by
        #5

        Sorry, but please walk me through it. The example and my code look identical to me.

        F L 2 Replies Last reply
        0
        • M Member 12244972

          Sorry, but please walk me through it. The example and my code look identical to me.

          F Offline
          F Offline
          F ES Sitecore
          wrote on last edited by
          #6

          You really need to understand the basics of c# before you try anything half-way complicated. We can't solve every basic problem you have. Get a book on c# and learn the fundamentals so you can solve these issues yourself, a forum is not a good place to learn something from scratch.

          1 Reply Last reply
          0
          • M Member 12244972

            Sorry, but please walk me through it. The example and my code look identical to me.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #7

            Please show the code and the error message, we cannot see your screen.

            M 1 Reply Last reply
            0
            • L Lost User

              Please show the code and the error message, we cannot see your screen.

              M Offline
              M Offline
              Member 12244972
              wrote on last edited by
              #8

              This exact line of code is where the error occurs:

                //Generate frequency for nw
                ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper((int)nw, Duration, 16383));
                //Generate frequency for nw
              

              Specifically the ThreadStart() function. The error is:

              Method name expected.

              L 1 Reply Last reply
              0
              • M Member 12244972

                This exact line of code is where the error occurs:

                  //Generate frequency for nw
                  ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper((int)nw, Duration, 16383));
                  //Generate frequency for nw
                

                Specifically the ThreadStart() function. The error is:

                Method name expected.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #9

                As shown on the link that Peter already gave you, the delegate creator needs the method name only. So your code should be:

                ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper);

                See also Creating Threads and Passing Data at Start Time[^].

                M 1 Reply Last reply
                0
                • L Lost User

                  As shown on the link that Peter already gave you, the delegate creator needs the method name only. So your code should be:

                  ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper);

                  See also Creating Threads and Passing Data at Start Time[^].

                  M Offline
                  M Offline
                  Member 12244972
                  wrote on last edited by
                  #10

                  Ok, but as you may see. The Beeper(); Function inputs 3 parameters (frequency, Duration and volume). The

                  ThreadStart(cacophony.Beeper);

                  does not pass these parameters or am I missing something?

                  L 1 Reply Last reply
                  0
                  • M Member 12244972

                    Ok, but as you may see. The Beeper(); Function inputs 3 parameters (frequency, Duration and volume). The

                    ThreadStart(cacophony.Beeper);

                    does not pass these parameters or am I missing something?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #11

                    Member 12244972 wrote:

                    or am I missing something?

                    Yes, what you are creating here is a delegate, not an immediate call to the beeper method. You need to spend more time reading the links you have been given to understand how delegates are used. See the tutorials on Events and Delegates at C# Tutorials (C#)[^].

                    M 1 Reply Last reply
                    0
                    • L Lost User

                      Member 12244972 wrote:

                      or am I missing something?

                      Yes, what you are creating here is a delegate, not an immediate call to the beeper method. You need to spend more time reading the links you have been given to understand how delegates are used. See the tutorials on Events and Delegates at C# Tutorials (C#)[^].

                      M Offline
                      M Offline
                      Member 12244972
                      wrote on last edited by
                      #12

                      Ok, removed the

                      ThreadStart(/*stuff*/); //Business...

                      and implemented a lambda...

                      Thread childThreadW = new Thread(unused => cacophony.Beeper((int)nw, Duration, 16383));

                      and my code builds fine now. Thank you all!

                      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