---
title: Upload models concurrently from .NET
summary: Upload a batch of models with one .NET client so the server checks them in at the same time, wait for all of them, read each result, and know what may run on which thread.
order: 15
languages: [csharp]
terms: [node, version, streaming-upload]
see-also: [how-to/models/upload-a-model, reference/dotnet, tutorials/dotnet/quick-start]
---

# Upload models concurrently from .NET

Checking in a model takes far longer than sending it: the server parses it, indexes it and generates its geometry. With the .NET client, `Upload.UploadModel` returns as soon as the file has been sent, with a task for the check-in. Starting all uploads first and waiting afterwards lets the server work on the whole batch at once.

## Before you start

The `BIM.works_SDK` package ([[page:how-to/install/dotnet]]), an API token with the `model:upload` scope and write rights on the target folder, and the files. [[page:how-to/models/upload-a-model]] explains a single upload, the deduplication check and what happens to a file with a name that already exists.

## Steps

```example
name: dotnet-concurrency
code: dotnet/concurrency.cs
notes: |
  Uploads every `.ifc` file of a directory into a folder `Batch` under the token's root. Run it twice and every model gets a second version, because the names exist.
highlight: 27,38,48,57
```

1. **Start every upload.** `client.Upload.UploadModel(builder)` sends the file and returns an `AsyncUploadTask` for its check-in. A failure to send the file throws `BimWorksException` right there; everything the check-in finds wrong comes with its result.
2. **Wait for all of them.** `GetTask()` is the `System.Threading.Tasks.Task` of a check-in, so `Task.WhenAll` (or `Task.WaitAll`) waits for the batch. One failed check-in does not stop the others.
3. **Read each result.** A task whose `Task` is faulted lost its connection and has no response: check `IsFaulted` first, because `Get()` and `GetUploadResponse()` wait for a response that never comes. Otherwise `GetUploadResponse()` returns the model node with its new version, or throws the error the server reported for that file.

## Threads

- Start the uploads from **one thread**. The client keeps a list of its running tasks that is not synchronised, and `UploadModel` adds to it.
- Waiting for the tasks and reading their results can happen on any thread.
- The files are sent one after another, each `UploadModel` call returning when its bytes are on the server; the check-ins run in parallel. To send the bytes of large files in parallel too, give each thread a client of its own: a factory can create several.
- The synchronous calls (`Fs`, `Bim.Query` and the others) only share the client's `HttpClient`, which is thread-safe.

## Check

Every file prints its version number and the status `OK`, and the `Batch` folder lists them all ([[page:how-to/models/list-the-tree]]).
