File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
daprdocs/content/en/dotnet-sdk-docs/dotnet-client Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments