Share via


EasmClient.CancelTaskAsync Method

Definition

Overloads

CancelTaskAsync(String, RequestContext)

[Protocol Method] Cancel a task by taskId.

CancelTaskAsync(String, CancellationToken)

Cancel a task by taskId.

CancelTaskAsync(String, RequestContext)

Source:
EasmClient.cs

[Protocol Method] Cancel a task by taskId.

public virtual System.Threading.Tasks.Task<Azure.Response> CancelTaskAsync (string taskId, Azure.RequestContext context);
abstract member CancelTaskAsync : string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CancelTaskAsync : string * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CancelTaskAsync (taskId As String, context As RequestContext) As Task(Of Response)

Parameters

taskId
String

The unique identifier of the task.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

taskId is null.

taskId is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call CancelTaskAsync and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
EasmClient client = new EasmClient(endpoint, credential);

Response response = await client.CancelTaskAsync("<taskId>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());

This sample shows how to call CancelTaskAsync with all parameters and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
EasmClient client = new EasmClient(endpoint, credential);

Response response = await client.CancelTaskAsync("<taskId>", null);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("startedAt").ToString());
Console.WriteLine(result.GetProperty("completedAt").ToString());
Console.WriteLine(result.GetProperty("lastPolledAt").ToString());
Console.WriteLine(result.GetProperty("state").ToString());
Console.WriteLine(result.GetProperty("phase").ToString());
Console.WriteLine(result.GetProperty("reason").ToString());
Console.WriteLine(result.GetProperty("metadata").GetProperty("<key>").ToString());

Applies to

CancelTaskAsync(String, CancellationToken)

Source:
EasmClient.cs

Cancel a task by taskId.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Defender.Easm.TaskResource>> CancelTaskAsync (string taskId, System.Threading.CancellationToken cancellationToken = default);
abstract member CancelTaskAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Defender.Easm.TaskResource>>
override this.CancelTaskAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Defender.Easm.TaskResource>>
Public Overridable Function CancelTaskAsync (taskId As String, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of TaskResource))

Parameters

taskId
String

The unique identifier of the task.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

taskId is null.

taskId is an empty string, and was expected to be non-empty.

Examples

This sample shows how to call CancelTaskAsync.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
EasmClient client = new EasmClient(endpoint, credential);

Response<TaskResource> response = await client.CancelTaskAsync("<taskId>");

This sample shows how to call CancelTaskAsync with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
EasmClient client = new EasmClient(endpoint, credential);

Response<TaskResource> response = await client.CancelTaskAsync("<taskId>");

Applies to