Share via

Threads Problems

swodniW 141 Reputation points
2021-05-23T11:01:59.157+00:00

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

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Duane Arnold 3,216 Reputation points
2021-05-23T11:43:35.407+00:00

@VBnetcoder-0336

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

https://learn.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://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1955

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Viorel 127K Reputation points
    2021-05-23T11:40:56.057+00:00

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

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. swodniW 141 Reputation points
    2021-05-23T13:27:31.15+00:00

    Thanks @Viorel and @Duane Arnold
    now i fixed everything thanks again

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.