---
title: "Find and fix blocking calls"
canonical: https://isoplane.dev/docs/how-to/find-and-fix-blocking-calls
---

# Find and fix blocking calls

A synchronous wait that would block throws `PlatformNotSupportedException` in
the sandbox, because an instance has one thread and nothing else on it could
ever satisfy the wait.
[Blocking waits and synchronous I/O](https://isoplane.dev/docs/concepts/dotnet-runtime-differences#blocking-waits)
explains the rule. This guide finds the blocking calls in an existing
application and replaces them.

## Build with the analyzer

The build reports a synchronous wait in your own code as
[`ISOPLANE1003`](https://isoplane.dev/docs/reference/error-codes#isoplane1003). To have it inspect
the NuGet packages you reference as well, set
[`IsoplaneAnalyzeDependencies`](https://isoplane.dev/docs/reference/project-settings#isoplaneanalyzedependencies)
in the project file and build:

```xml
<PropertyGroup>
  <IsoplaneAnalyzeDependencies>true</IsoplaneAnalyzeDependencies>
</PropertyGroup>
```

```bash
dotnet build
```

Each warning names the call and where it is. In the editor the warning sits on
the call itself, with a quick fix that awaits instead.

Some blocking calls don't look like waits at all, such as reading
`Request.Form` before the form has been read, or disposing a data reader that
still has unread rows.
[Calls that block without looking like waits](https://isoplane.dev/docs/concepts/library-compatibility#hidden-blocking-calls)
lists the ones we know of, with their async forms.

## Replace each call

Use the async form of each call. The most common replacements:

| Blocking call                                                 | Use instead                           |
| ------------------------------------------------------------- | ------------------------------------- |
| `task.Wait()`, `task.Result`, `task.GetAwaiter().GetResult()` | `await task`                          |
| `Task.WaitAll(...)`                                           | `await Task.WhenAll(...)`             |
| `Thread.Sleep(...)`                                           | `await Task.Delay(...)`               |
| `semaphore.Wait()`                                            | `await semaphore.WaitAsync()`         |
| `SaveChanges()`, `ToList()` on an EF Core context             | `SaveChangesAsync()`, `ToListAsync()` |

Making one method async usually means making its callers async too. Work
outward from each call until you reach the request handler, which is already
async.

## Check the libraries you use

A library can block inside a call that looks asynchronous, or offer no async
API at all. [Library compatibility](https://isoplane.dev/docs/concepts/library-compatibility)
lists the libraries known to do so, with what to use in their place.

## Run the application

Anything left throws when it is reached, not before. Run the application and
its tests as [Run and rebuild](https://isoplane.dev/docs/how-to/run-and-rebuild) and
[Test an application](https://isoplane.dev/docs/how-to/test-an-application) describe. A remaining blocking
wait fails its request with status 500, and the session log shows
`request failed: System.PlatformNotSupportedException` with a stack trace that
names the call.
