Skip to content

Commit 364ed92

Browse files
authored
[dotnet-client] Add dist lock examples (#1095)
* add dist lock to dotnet client doc Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com> * attempt at naming scheme 1 Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com> * yikes put it back Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com> * attempt 2 Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com> * attempt 3 Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com> --------- Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
1 parent e59c856 commit 364ed92

File tree

1 file changed

+58
-0
lines changed
  • daprdocs/content/en/dotnet-sdk-docs/dotnet-client

1 file changed

+58
-0
lines changed

daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,64 @@ await foreach (var items in subscribeConfigurationResponse.Source.WithCancellati
199199
}
200200
```
201201

202+
### Distributed lock (Alpha)
203+
204+
#### Acquire a lock
205+
206+
```csharp
207+
using System;
208+
using Dapr.Client;
209+
210+
namespace LockService
211+
{
212+
class Program
213+
{
214+
[Obsolete("Distributed Lock API is in Alpha, this can be removed once it is stable.")]
215+
static async Task Main(string[] args)
216+
{
217+
var daprLockName = "lockstore";
218+
var fileName = "my_file_name";
219+
var client = new DaprClientBuilder().Build();
220+
221+
// Locking with this approach will also unlock it automatically, as this is a disposable object
222+
await using (var fileLock = await client.Lock(DAPR_LOCK_NAME, fileName, "random_id_abc123", 60))
223+
{
224+
if (fileLock.Success)
225+
{
226+
Console.WriteLine("Success");
227+
}
228+
else
229+
{
230+
Console.WriteLine($"Failed to lock {fileName}.");
231+
}
232+
}
233+
}
234+
}
235+
}
236+
```
237+
238+
#### Unlock an existing lock
239+
240+
```csharp
241+
using System;
242+
using Dapr.Client;
243+
244+
namespace LockService
245+
{
246+
class Program
247+
{
248+
static async Task Main(string[] args)
249+
{
250+
var daprLockName = "lockstore";
251+
var client = new DaprClientBuilder().Build();
252+
253+
var response = await client.Unlock(DAPR_LOCK_NAME, "my_file_name", "random_id_abc123"));
254+
Console.WriteLine(response.status);
255+
}
256+
}
257+
}
258+
```
259+
202260
### Manage workflow instances (Alpha)
203261

204262
```csharp

0 commit comments

Comments
 (0)