SnowFlakeSingle.cs 856 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SqlSugar
  7. {
  8. public sealed class SnowFlakeSingle
  9. {
  10. private static object LockObject = new object();
  11. private static DistributedSystem.Snowflake.IdWorker worker;
  12. public static int WorkId = 1;
  13. public static int DatacenterId = 1;
  14. private SnowFlakeSingle()
  15. {
  16. }
  17. static SnowFlakeSingle() { }
  18. public static DistributedSystem.Snowflake.IdWorker Instance
  19. {
  20. get
  21. {
  22. if (worker == null)
  23. {
  24. lock (LockObject)
  25. {
  26. if (worker == null)
  27. {
  28. worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
  29. }
  30. }
  31. }
  32. return worker;
  33. }
  34. }
  35. public static DistributedSystem.Snowflake.IdWorker instance
  36. {
  37. get
  38. {
  39. return Instance;
  40. }
  41. }
  42. }
  43. }