Skip to content

Commit c0e23c1

Browse files
authored
Blazor sync context updates (#18242)
1 parent 41ab9bd commit c0e23c1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

aspnetcore/blazor/components.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to create and use Razor components, including how to bind
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/21/2020
8+
ms.date: 05/11/2020
99
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
1010
uid: blazor/components
1111
---
@@ -306,9 +306,11 @@ While capturing component references use a similar syntax to [capturing element
306306
307307
## Invoke component methods externally to update state
308308

309-
Blazor uses a `SynchronizationContext` to enforce a single logical thread of execution. A component's [lifecycle methods](xref:blazor/lifecycle) and any event callbacks that are raised by Blazor are executed on this `SynchronizationContext`. In the event a component must be updated based on an external event, such as a timer or other notifications, use the `InvokeAsync` method, which will dispatch to Blazor's `SynchronizationContext`.
309+
Blazor uses a synchronization context (`SynchronizationContext`) to enforce a single logical thread of execution. A component's [lifecycle methods](xref:blazor/lifecycle) and any event callbacks that are raised by Blazor are executed on the synchronization context.
310310

311-
For example, consider a *notifier service* that can notify any listening component of the updated state:
311+
Blazor Server's synchronization context attempts to emulate a single-threaded environment so that it closely matches the WebAssembly model in the browser, which is single threaded. At any given point in time, work is performed on exactly one thread, giving the impression of a single logical thread. No two operations execute concurrently.
312+
313+
In the event a component must be updated based on an external event, such as a timer or other notifications, use the `InvokeAsync` method, which will dispatch to Blazor's synchronization context. For example, consider a *notifier service* that can notify any listening component of the updated state:
312314

313315
```csharp
314316
public class NotifierService
@@ -373,7 +375,7 @@ Use the `NotifierService` to update a component:
373375
}
374376
```
375377

376-
In the preceding example, `NotifierService` invokes the component's `OnNotify` method outside of Blazor's `SynchronizationContext`. `InvokeAsync` is used to switch to the correct context and queue a render.
378+
In the preceding example, `NotifierService` invokes the component's `OnNotify` method outside of Blazor's synchronization context. `InvokeAsync` is used to switch to the correct context and queue a render.
377379

378380
## Use \@key to control the preservation of elements and components
379381

0 commit comments

Comments
 (0)