Beispiel #1
0
 public string GetNextSerial()
 {
     // ThreadSafeSerial is thread-safe, so we're good, yes?
     //
     // No, because we may get more than one instance of it!
     //
     // You need to ensure that we only get one instance. Try at least the following: -
     // * Lazy<T> - experiment with the LazyThreadSafetyMode
     // * LazyInitializer<T> - look at the different signatures
     //
     // The above will use a lock internally. Can you avoid it? I haven't managed to!
     serial = serial ?? new ThreadSafeSerial(DateTime.Now.ToShortDateString());
     return(serial.GetNextSerial());
 }
 public string GetNextSerial()
 {
     // ThreadSafeSerial is thread-safe, so we're good, yes?
     //
     // No, because we may get more than one instance of it!
     //
     // You need to ensure that we only get one instance. Try at least the following: -
     // * Lazy<T> - experiment with the LazyThreadSafetyMode
     // * LazyInitializer<T> - look at the different signatures
     //
     // The above will use a lock internally. Can you avoid it? I haven't managed to!
     serial = serial ?? new ThreadSafeSerial(DateTime.Now.ToShortDateString());
     return serial.GetNextSerial();
 }