DbContext.SaveChangesAsync Method (CancellationToken)

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Asynchronously saves all changes made in this context to the underlying database.

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId := "cancellationToken")> _
Public Overridable Function SaveChangesAsync ( _
    cancellationToken As CancellationToken _
) As Task(Of Integer)
'Usage
Dim instance As DbContext 
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of Integer)

returnValue = instance.SaveChangesAsync(cancellationToken)
[SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "cancellationToken")]
public virtual Task<int> SaveChangesAsync(
    CancellationToken cancellationToken
)
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA1801:ReviewUnusedParameters", MessageId = L"cancellationToken")]
public:
virtual Task<int>^ SaveChangesAsync(
    CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "cancellationToken")>]
abstract SaveChangesAsync : 
        cancellationToken:CancellationToken -> Task<int> 
[<SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "cancellationToken")>]
override SaveChangesAsync : 
        cancellationToken:CancellationToken -> Task<int> 
public function SaveChangesAsync(
    cancellationToken : CancellationToken
) : Task<int>

Parameters

Return Value

Type: System.Threading.Tasks.Task<Int32>
A task that represents the asynchronous save operation. The task result contains the number of objects written to the underlying database.

Exceptions

Exception Condition
InvalidOperationException

Thrown if the context has been disposed.

Remarks

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

See Also

Reference

DbContext Class

SaveChangesAsync Overload

System.Data.Entity Namespace