I am implementing this class as a singleton. I am not good at thread safety. Wanted to make sure the GenerateOrderID class is thread safe. More specifically that the orderCount variable cannot be incremented simultaneously by different objects and throw the count off.
public class OrderIDGenerator
{
private static readonly OrderIDGenerator instance = new OrderIDGenerator();
private int orderCount;
private OrderIDGenerator()
{
orderCount = 1;
}
public static OrderIDGenerator Instance
{
get { return instance; }
}
public string GenerateOrderID()
{
return String.Format("{0:yyyyMMddHHmmss}{1}", DateTime.Now, orderCount++);
}
}