DistributedLeaseManager
2.0.0
การใช้งาน C#/. NET แบบกระจาย/Lock Manager (DLM)
แรงบันดาลใจจาก https://github.com/fbeltrao/azfunctions-distributed-locking
ติดตั้งหนึ่งในการใช้งานการจัดเก็บสัญญาเช่าโดยทำตามคำแนะนำ ReadMe ของพวกเขา:
ภายในคอนโทรลเลอร์/บริการของคุณฉีด IDistributedLeaseManager และโทรหาวิธีการ TryAcquireLease ตรวจสอบว่าผลลัพธ์นั้นประสบความสำเร็จ - ถ้าเป็นเช่นนั้นคุณสามารถดำเนินการดำเนินการต่อไปได้ มิฉะนั้นคนอื่นได้รับสัญญาเช่า:
await using var leaseResult = await leaseManager . TryAcquireLease ( resourceId , TimeSpan . FromSeconds ( 5 ) ) ;
if ( ! leaseResult . IsSuccessful )
{
// Someone else has required the lease for the resource.
// You may want to either retry the acqusition or abort the operation.
}
else
{
// You are the lease owner now and can safely process the resource.
// The lease will be released either when the leaseResult gets disposed
// or when the lease expires (in the example above, in 5 seconds)
} หากคุณต้องการใช้ที่เก็บข้อมูลการเช่าที่แตกต่างจากที่จัดทำโดยผู้เขียนให้เพิ่ม DistributedLeaseManager.Core Library ไปยังโครงการของคุณและใช้อินเทอร์เฟซที่เกี่ยวข้อง (ดูการใช้งานที่มีอยู่เป็นตัวอย่าง)
อย่าลังเลที่จะเปิดประชาสัมพันธ์ด้วยการเปลี่ยนแปลงของคุณเพื่อรวมไว้ในแพ็คเกจ!