I'm starting to learn threading and have encountered a problem.
I have a scoring system that is designed to add a point to a temporary addedPoints variable to show the player how many points they have recently earned. Then after about 1 second the added points should be added to the players score.
My attempt looks like this:
public static void AddPoints(int points)
{
for (int i = 0; i < points; i++)
{
Thread addThread = new Thread(new ThreadStart(ThreadedPoint));
}
}
private static void ThreadedPoint()
{
addedPoints += 1;
Thread.Sleep(1000);
score += 1;
addedPoints -= 1;
}
This has two problems. First it only allows me to add 1 point per thread which is far from ideal. Second it doesn't actually work. Neither addedPoints nor score is updated. How can I fix this?