Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Every time I attempt to create a new Thread floodT = new Thread(new ThreadStart(fn.Flood(fcmd));, it will always give me an error telling me "Method name expected."

I am completely lost, and I've been on MSDN reading an old archived tutorial about threading methods. (Threading Tutorial (C#)[^]) I think I've been working on this for probably an hour. I'm just stuck.

Please help, and thanks a lot in advance!

HINT: All the important code starts in the FloodCmd() method.

My code:
C#
public class Command
    {
    public void Help()
        {
            ... Some other really really long code goes here, but I saved you reading time. Oh, and since you're here, I'm a thirteen year old programmer, and message me on Skype: facebook:luke.wilson.1293575 Okay, now I need to get back to this, because I have mad ADD xc
        }

        public class Network
        {
            public void FloodCmd(String address)
            {
                var fcmd = address.Remove(0, 6);    // Get rid of "FLOOD " in the cmd, leaving it with the address.

                try
                {
                    Ping ping = new Ping();
                    // NOTE ABOUT THREADS: for some reason they have to be in an entirely different
                    // master-class.
                    NetTools fn = new NetTools();
                    Thread floodT = new Thread(new ThreadStart(fn.Flood(fcmd)));    // This right here is the code it's giving me syntax errors for. HELP!

                    floodT.Start();
                    ping.Send(fcmd);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.Write("Error in flood: " + e.Message);
                    Program.WriteError(e.Message);
                }
            }
        }
    }

    public class NetTools
    {
        public void Flood (String address)
        {
            while (true)
            try
            {
                Ping ping = new Ping();

                ping.Send(address);
            }
            catch (Exception e)
            {
                Program.WriteError(e.Message);
            }
        }
    }


What I have tried:

I've looked all over the internet for tutorials, and I remembered how nice this community is. And I'd like to bring my difficulties to the public for everyone to learn a little bit from.
Posted
Updated 19-May-16 14:58pm

First, your comment is wrong: there's no requirement for threads to be in a different class. You just have to be careful about what you're referencing.

This has the appearance of the beginnings of a DoS attack program.
Don't go there!
C#
NetTools fn = new NetTools();
Thread floodT = new Thread(new ThreadStart(() => fn.Flood(fcmd)));
floodT.Start();

Is one way to solve this.
Another:
C#
NetTools fn = new NetTools();
Thread floodT = new Thread(new ParameterizedThreadStart(fn.Flood));
floodT.Start(fcmd);

and add
C#
public void Flood (object address)
{
  Flood(address as string);
}

In fact, your Flood method(s) can all be static.
This changes the above to eliminate the
NetTools fn = new NetTools();
line and change the
fn.Flood
to
NetTools.Flood
 
Share this answer
 
Comments
VenHayz 19-May-16 21:10pm    
Thanks a lot. It's actually not a DDoS attack program. I'm just coding one function out of the hundreds in the terminal. It's just a pen-tester's terminal. And basically a simpler Windows Powershell.
I think what you are looking for is this: ParameterizedThreadStart Delegate (System.Threading)[^]
There is a working example there that you can use as a starting point.

This link also contains information about threads: Creating Threads and Passing Data at Start Time[^]

As for a tutorial you can read this article: Beginners Guide to Threading in .NET: Part 1 of n[^]
 
Share this answer
 
Comments
VenHayz 19-May-16 21:11pm    
Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900