The name 'Beeper' does not exist in the current context
-
Beeper
is a member function ofSinger
(the class)... Calling it likeBeeper
alone will only work when you are in the context ofSinger
(from other members for instance). If you are out of that context you have to tell the compiler the new/actual context... in your casecacophony
... 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.
Ok, now the error is:
Method name expected.
Any ideas?
-
Ok, now the error is:
Method name expected.
Any ideas?
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.
-
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.
Sorry, but please walk me through it. The example and my code look identical to me.
-
Sorry, but please walk me through it. The example and my code look identical to me.
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.
-
Sorry, but please walk me through it. The example and my code look identical to me.
-
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.
-
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.
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[^].
-
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[^].
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?
-
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?
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#)[^].
-
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#)[^].
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!