---
title: AsyncTask
summary: Class in BIM.works_SDK.
order: 10
languages: [csharp]
sdk-package: .NET · BIM.works_SDK
---

# AsyncTask

[[page:reference/dotnet/api|API catalogue]] · `BIM.works_SDK` · Class

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public class AsyncTask
````

A request executed in a background Task, with an optional progress subscription.

Create through BimWorksClient.CreateAsyncTask(request), then call Execute() once.
    Await GetTask() to observe transport faults before reading Get(); Get() alone blocks and does not rethrow stored server errors.
    This API has no cancellation-token or timed-wait overload.

## Example

<pre><code class="lang-csharp">AsyncTask pending = client.CreateAsyncTask(request);
pending.Execute();
await pending.GetTask();
if (pending.IsError()) throw pending.GetException();
Response result = pending.Get() ?? throw new InvalidOperationException("No successful response.");
JsonElement output = result.GetOutput();</code></pre>

## Inheritance and interfaces

- `System.Object`

## Members

| Member | Kind | Description |
|---|---|---|
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-ctor-2e223718cc92|AsyncTask(BimWorksClient, Request)]] | Constructor | Creates an unstarted request. Prefer the client's CreateAsyncTask method, which also registers it for progress dispatch. |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-addprogresslistener-bc66e2a4284e|AddProgressListener(ProgressListener)]] | Method | Registers a listener locally and subscribes to progress updates for this request. |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-execute-66655585d836|Execute()]] | Method | Starts the HTTP request on a background Task. Call once per instance. Server errors are stored for IsError()/GetException(); transport faults fault GetTask()… |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-get-4793d8809ee3|Get()]] | Method | Blocks until the response latch is signalled, then reads the response. This method does not start execution or throw the stored server exception. Await GetTa… |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-getexception-4ef7a6cdf25f|GetException()]] | Method | Reads the server exception recorded by Execute(). |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-getid-70c860704b13|GetId()]] | Method | Gets the request identifier used by the server's progress subscription. |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-gettask-9d5478b73ae5|GetTask()]] | Method | Gets the background operation started by Execute(). Awaiting this observes transport faults. Server error envelopes must also be checked with IsError() and G… |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-iserror-2a5a77fdfd0f|IsError()]] | Method | Checks whether a server error has been stored. Transport faults are reported by GetTask(), so await it before checking this method. |
| [[page:reference/dotnet/bim-works-sdk/asynctask-86c57ccc#member-updateprogress-7a9e88540638|UpdateProgress(ProgressUpdate)]] | Method | Dispatches a received progress update to registered listeners. Called by the client when an update arrives; applications normally register listeners instead. |

## `AsyncTask(BimWorksClient, Request)` {#member-ctor-2e223718cc92}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public AsyncTask(BimWorksClient bimWorksClient, Request request)
````

Creates an unstarted request. Prefer the client's CreateAsyncTask method, which also registers it for progress dispatch.

### Parameters

| Name | Type | Description |
|---|---|---|
| `bimWorksClient` | [[page:reference/dotnet/bim-works-sdk/bimworksclient-38b8aecc|BimWorksClient]] | Client that supplies authentication and the HTTP transport. |
| `request` | [[page:reference/dotnet/bim-works-sdk/request-0158d899|Request]] | Request to execute; its id identifies the task. |

## `AddProgressListener(ProgressListener)` {#member-addprogresslistener-bc66e2a4284e}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public void AddProgressListener(ProgressListener progressListener)
````

Registers a listener locally and subscribes to progress updates for this request.

### Parameters

| Name | Type | Description |
|---|---|---|
| `progressListener` | [[page:reference/dotnet/bim-works-sdk/progresslistener-78bb6d83|ProgressListener]] | Listener whose Progress(label, progress) method receives updates. |

### Exceptions

- `BIM.works_SDK.BimWorksException` — The server rejects the progress subscription.

## `Execute()` {#member-execute-66655585d836}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public AsyncTask Execute()
````

Starts the HTTP request on a background Task. Call once per instance.

Server errors are stored for IsError()/GetException(); transport faults fault GetTask(). A non-success HTTP status may leave Get() null.

### Returns

This AsyncTask, for chaining.

## `Get()` {#member-get-4793d8809ee3}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public Response Get()
````

Blocks until the response latch is signalled, then reads the response.

This method does not start execution or throw the stored server exception. Await GetTask() first: transport faults can occur before the latch is signalled. Then check IsError() and GetException().

### Returns

The response, or null when no successful HTTP response was stored.

## `GetException()` {#member-getexception-4ef7a6cdf25f}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public Exception GetException()
````

Reads the server exception recorded by Execute().

### Returns

The stored exception, or null if no server error has been recorded.

## `GetId()` {#member-getid-70c860704b13}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public Guid GetId()
````

Gets the request identifier used by the server's progress subscription.

### Returns

The request's UUID.

## `GetTask()` {#member-gettask-9d5478b73ae5}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public Task GetTask()
````

Gets the background operation started by Execute().

Awaiting this observes transport faults. Server error envelopes must also be checked with IsError() and GetException().

### Returns

The awaitable Task, or null before Execute() has been called.

## `IsError()` {#member-iserror-2a5a77fdfd0f}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public bool IsError()
````

Checks whether a server error has been stored.

Transport faults are reported by GetTask(), so await it before checking this method.

### Returns

True after an error envelope was received; false otherwise, including before completion.

## `UpdateProgress(ProgressUpdate)` {#member-updateprogress-7a9e88540638}

````csharp sdk=dotnet sdk-namespace="BIM.works_SDK"
public void UpdateProgress(ProgressUpdate progressUpdate)
````

Dispatches a received progress update to registered listeners.

Called by the client when an update arrives; applications normally register listeners instead.

### Parameters

| Name | Type | Description |
|---|---|---|
| `progressUpdate` | [[page:reference/dotnet/bim-works-sdk/progressupdate-4f71bdb4|ProgressUpdate]] | Progress label and value supplied by the server. |

## Inherited members

- `System.Object.Equals(System.Object)`
- `System.Object.Equals(System.Object,System.Object)`
- `System.Object.GetHashCode`
- `System.Object.GetType`
- `System.Object.MemberwiseClone`
- `System.Object.ReferenceEquals(System.Object,System.Object)`
- `System.Object.ToString`
