public class LimitedConcurrencyLevelTaskScheduler : TaskScheduler { // Indicates whether the current thread is processing work items. [ThreadStatic] private static bool _currentThreadIsProcessingItems; // The maximum concurrency level allowed by this
背景:用户领取优惠券,同一个用户需要加锁验证是否已经领取,不同用户则可以同时领取. 上代码示例: 1.创建Person类 /// <summary> /// Person类 /// </summary> public class Person { /// <summary> /// id /// </summary> public int Id { get; set; } /// <summary> /// 姓名 /// </summary