Skip to content

Commit

Permalink
[dotnet-client] Add dist lock examples (#1095)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hhunter-ms authored May 22, 2023
1 parent e59c856 commit 364ed92
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,64 @@ await foreach (var items in subscribeConfigurationResponse.Source.WithCancellati
}
```

### Distributed lock (Alpha)

#### Acquire a lock

```csharp
using System;
using Dapr.Client;

namespace LockService
{
class Program
{
[Obsolete("Distributed Lock API is in Alpha, this can be removed once it is stable.")]
static async Task Main(string[] args)
{
var daprLockName = "lockstore";
var fileName = "my_file_name";
var client = new DaprClientBuilder().Build();

// Locking with this approach will also unlock it automatically, as this is a disposable object
await using (var fileLock = await client.Lock(DAPR_LOCK_NAME, fileName, "random_id_abc123", 60))
{
if (fileLock.Success)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine($"Failed to lock {fileName}.");
}
}
}
}
}
```

#### Unlock an existing lock

```csharp
using System;
using Dapr.Client;

namespace LockService
{
class Program
{
static async Task Main(string[] args)
{
var daprLockName = "lockstore";
var client = new DaprClientBuilder().Build();

var response = await client.Unlock(DAPR_LOCK_NAME, "my_file_name", "random_id_abc123"));
Console.WriteLine(response.status);
}
}
}
```

### Manage workflow instances (Alpha)

```csharp
Expand Down

0 comments on commit 364ed92

Please sign in to comment.