The analyzer detected a suspicious code fragment where an object of type 'Thread' is created but the new thread is not started.
Consider the following example:
void Foo(ThreadStart action)
{
Thread thread = new Thread(action);
thread.Name = "My Thread";
}
In this code, an object of type 'Thread' is created, and the reference to it is written into the 'thread' variable. However, the thread itself is not started or passed anywhere. Therefore, the created object, which will not have been used in any way, will simply be erased the next time garbage collection occurs.
To fix this error, we need to call the object's 'Start' method, which will start the thread. The fixed code should look something like this:
void Foo(ThreadStart action)
{
Thread thread = new Thread(action);
thread.Name = "My Thread";
thread.Start();
}
This diagnostic is classified as: