Share via


EasmClient.CancelTask Method

Definition

Overloads

CancelTask(String, RequestContext)

[Protocol Method] Cancel a task by taskId.

CancelTask(String, CancellationToken)

Cancel a task by taskId.

CancelTask(String, RequestContext)

Source:
EasmClient.cs

[Protocol Method] Cancel a task by taskId.

public virtual Azure.Response CancelTask (string taskId, Azure.RequestContext context);
abstract member CancelTask : string * Azure.RequestContext -> Azure.Response
override this.CancelTask : string * Azure.RequestContext -> Azure.Response
Public Overridable Function CancelTask (taskId As String, context As RequestContext) As 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 CancelTask 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 = client.CancelTask("<taskId>", null);

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

This sample shows how to call CancelTask 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 = client.CancelTask("<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

CancelTask(String, CancellationToken)

Source:
EasmClient.cs

Cancel a task by taskId.

public virtual Azure.Response<Azure.Analytics.Defender.Easm.TaskResource> CancelTask (string taskId, System.Threading.CancellationToken cancellationToken = default);
abstract member CancelTask : string * System.Threading.CancellationToken -> Azure.Response<Azure.Analytics.Defender.Easm.TaskResource>
override this.CancelTask : string * System.Threading.CancellationToken -> Azure.Response<Azure.Analytics.Defender.Easm.TaskResource>
Public Overridable Function CancelTask (taskId As String, Optional cancellationToken As CancellationToken = Nothing) As 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 CancelTask.

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

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

This sample shows how to call CancelTask 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 = client.CancelTask("<taskId>");

Applies to