共用方式為


IReliableDictionary<TKey,TValue>.SetAsync Method

Definition

Overloads

SetAsync(ITransaction, TKey, TValue)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary if the key already exists.

SetAsync(ITransaction, TKey, TValue, TimeSpan, CancellationToken)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary if the key already exists.

SetAsync(ITransaction, TKey, TValue)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary if the key already exists.

public System.Threading.Tasks.Task SetAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue value);
abstract member SetAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value -> System.Threading.Tasks.Task
Public Function SetAsync (tx As ITransaction, key As TKey, value As TValue) As Task

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key whose value should be updated.

value
TValue

The value that replaces the value of the element that has the specified key.

Returns

A task that represents the asynchronous update operation.

Exceptions

tx is null, or key is null or cannot be serialized.

The operation failed to complete within the default timeout.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to

SetAsync(ITransaction, TKey, TValue, TimeSpan, CancellationToken)

Adds a key/value pair to the Reliable Dictionary if the key does not already exist, or updates a key/value pair in the Reliable Dictionary if the key already exists.

public System.Threading.Tasks.Task SetAsync (Microsoft.ServiceFabric.Data.ITransaction tx, TKey key, TValue value, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
abstract member SetAsync : Microsoft.ServiceFabric.Data.ITransaction * 'Key * 'Value * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function SetAsync (tx As ITransaction, key As TKey, value As TValue, timeout As TimeSpan, cancellationToken As CancellationToken) As Task

Parameters

tx
ITransaction

Transaction to associate this operation with.

key
TKey

The key whose value should be updated.

value
TValue

The value that replaces the value of the element that has the specified key.

timeout
TimeSpan

The amount of time to wait for the operation to complete before throwing a TimeoutException. Primarily used to prevent deadlocks. The default is 4 seconds.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default is None.

Returns

A task that represents the asynchronous update operation.

Exceptions

tx is null, or key is null or cannot be serialized.

timeout is negative.

The operation failed to complete within the given timeout.

The operation was canceled.

The exception that is thrown when the IReliableDictionary<TKey,TValue> is not in Primary.

The transaction has been internally faulted by the system. Retry the operation on a new transaction

Thrown when a method call is invalid for the object's current state. Example, transaction used is already terminated: committed or aborted by the user. If this exception is thrown, it is highly likely that there is a bug in the service code of the use of transactions.

Indicates that the Reliable Dictionary is closed or deleted.

Applies to