Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static void StartClientThread(TcpClient client, NotifyBringNewSocket notify)
{
    ProcessTCPClient.notify = notify;
    Thread t = new Thread(ClientThread);
    t.Start(client);
}
private static void ClientThread(TcpClient client)
{
    NetworkStream network;
    try
    {
        network = client.GetStream();
    }
    catch (Exception ex)
    {
        notify.Invoke();
        return;
    }

    // know if it is SSL connection
    string hdr = ReadHeader(network);
    if (hdr == "")
    {
        notify.Invoke();
        return;
    }
    if (hdr.Contains("EXIT"))
    {
        IS_RUNNING = false;
        CleanUp();
        Application.Exit();
        return;
    }
    try
    {
        TcpClient extSoc = new TcpClient("127.0.0.1", 3389);

        SSLReadWrite ssl = new SSLReadWrite();
        ssl.StartSSLReadWriteThread(client, network, extSoc, notify);
        notify.Invoke();
    }
    catch (Exception ex)
    {
        notify.Invoke();
        client.Close();
    }
}




this part :
public static void StartClientThread(TcpClient client, NotifyBringNewSocket notify)
{
    ProcessTCPClient.notify = notify;
    Thread t = new Thread(ClientThread);
    t.Start(client);
}


Thread t = new Thread(ClientThread);
has this error :
CS1503 Argument 1: cannot convert from 'method group' to 'ThreadStart'

What I have tried:

i have try to fix it like this : 
public static void StartClientThread(TcpClient client, NotifyBringNewSocket notify)
    {
        ProcessTCPClient.notify = notify;
        Thread t = new Thread(() => ClientThread(client));
        t.Start(client);
    }

but my code is not working
Posted
Updated 17-Feb-20 4:10am

You must pass a ThreadStart to the Thread constructor.
See the documentation[^] for details an code samples.

[update]
Change from
Quote:
Thread t = new Thread(ClientThread);
to
C#
Thread t = new Thread(new ThreadStart(ClientThread));
[/update]


[update II]
Your method should take an object as argument:
C#
private static void ClientThread(object objclient)
{
  TcpClient client = (TcpClient) objclient;
  // ...



[/update II]
 
Share this answer
 
v3
Comments
CyberSecII 17-Feb-20 5:41am    
can you show me how?
CPallini 17-Feb-20 6:04am    
The documentation already does. Anyway, have a look at my updated solution.
CyberSecII 17-Feb-20 9:27am    
no that does't work i got errors :(
No overload for 'ClientThread' matches delegate 'ThreadStart' Client
CPallini 17-Feb-20 9:48am    
Yep, you're right.
My bad, I misunderstood the problem.
Your ClientThread function must take an object as argument, in order to use the ParameterizedThreadStart delegate. See, again, my updated solution
CyberSecII 25-Mar-20 19:00pm    
Thank you for taking the time to help me!!
C#
public static void StartClientThread(TcpClient client, NotifyBringNewSocket notify)
    {
        ProcessTCPClient.notify = notify;
        Thread t = new Thread(() => ClientThread(client));
        t.Start(); // I removed the parameter as it is being passed in the call in the line above
    }
 
Share this answer
 
Comments
CyberSecII 17-Feb-20 12:34pm    
Thank you!! That fixed the error!!

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