question

SharpWindows avatar image
0 Votes"
SharpWindows asked SharpWindows answered

Threads Problems

Hello,
I have a problem. I am learning how to use threads.
I was writing an example of code but there's something wrong.

  class Program
     { 
         public delegate void ThreadStart();
    
         void MN()
         {
             Thread th = new Thread(ThreadStart(CodiceSecondario));   //CS1955
         }
         void CodiceSecondario()
         {
             //Do something
         }
     }

I didn't undersrand the error.
Thanks in advance

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
1 Vote"
DuaneArnold-0443 answered DuaneArnold-0443 edited

@VBnetcoder-0336


You can omit the ThreadStart() in your situation, which is being talked about in the Note.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.parameterizedthreadstart?view=net-5.0

The ThreadStart() is suppose to pass a parameter to the delegate method and you are trying to pass a method().

https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1955

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SharpWindows avatar image
0 Votes"
SharpWindows answered

Thanks @Viorel-1 and @DuaneArnold-0443
now i fixed everything thanks again

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

Remove your definition of ThreadStart and try this: Thread th = new Thread( CodiceSecondario ).


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.