如何避免任務重複執行

喜爱糖葫芦發表於2024-03-19

提問

如何避免任務重複執行

回答

public readonly SemaphoreSlim semaphore = new(1);
semaphore..Wait();
//do something
...
//做完了
semaphore.Release();

參考

https://learn.microsoft.com/zh-cn/dotnet/api/system.threading.semaphoreslim?view=net-6.0

相關文章