Skip to content

Commit 70d3bec

Browse files
committed
Migrate docs to docfx-based GitHub Pages
1 parent e9525db commit 70d3bec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1540
-1466
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<!-- Local builds should embed PDBs so we never lose them when a subsequent build occurs. -->
2525
<DebugType Condition=" '$(CI)' != 'true' and '$(TF_BUILD)' != 'true' ">embedded</DebugType>
2626

27-
<PackageProjectUrl>https://github.com/Microsoft/vs-threading</PackageProjectUrl>
27+
<PackageProjectUrl>https://microsoft.github.io/vs-threading/</PackageProjectUrl>
2828
<Company>Microsoft</Company>
2929
<Authors>Microsoft</Authors>
3030
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99

1010
Async synchronization primitives, async collections, TPL and dataflow extensions. The JoinableTaskFactory allows synchronously blocking the UI thread for async work. This package is applicable to any .NET application (not just Visual Studio).
1111

12-
[Overview documentation](doc/index.md).
12+
[Getting started](https://microsoft.github.io/vs-threading/docs/getting-started.md).
1313

14-
[See the full list of features](src/Microsoft.VisualStudio.Threading/README.md).
14+
[See the full list of features](https://microsoft.github.io/vs-threading/docs/features.md).
1515

1616
## Microsoft.VisualStudio.Threading.Analyzers
1717

1818
[![NuGet package](https://img.shields.io/nuget/v/Microsoft.VisualStudio.Threading.Analyzers.svg)](https://www.nuget.org/packages/Microsoft.VisualStudio.Threading.Analyzers)
1919

2020
Static code analyzer to detect common mistakes or potential issues regarding threading and async coding.
2121

22-
[Diagnostic analyzer rules](doc/analyzers/index.md).
23-
24-
[See the full list of features](src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/README.md).
22+
[Diagnostic analyzer rules](https://microsoft.github.io/vs-threading/analyzers/index.md).

doc/analyzers/VSTHRD001.md

+1-82
Original file line numberDiff line numberDiff line change
@@ -1,82 +1 @@
1-
# VSTHRD001 Avoid legacy thread switching methods
2-
3-
Switching to the UI thread should be done using `JoinableTaskFactory.SwitchToMainThreadAsync`
4-
rather than legacy methods such as `Dispatcher.Invoke` or `ThreadHelper.Invoke`.
5-
This avoids deadlocks and can reduce threadpool starvation.
6-
7-
## Examples of patterns that are flagged by this analyzer
8-
9-
```csharp
10-
ThreadHelper.Generic.Invoke(delegate {
11-
DoSomething();
12-
});
13-
```
14-
15-
or
16-
17-
```cs
18-
Dispatcher.CurrentDispatcher.BeginInvoke(delegate {
19-
DoSomething();
20-
});
21-
```
22-
23-
## Solution
24-
25-
Use `await SwitchToMainThreadAsync()` instead, wrapping with the `JoinableTaskFactory`'s `Run` or `RunAsync` method if necessary:
26-
27-
```csharp
28-
void Foo() {
29-
ThreadHelper.JoinableTaskFactory.Run(async delegate {
30-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
31-
DoSomething();
32-
});
33-
}
34-
```
35-
36-
In the above example, we obtain a `JoinableTaskFactory` instance from the `ThreadHelper.JoinableTaskFactory` static property
37-
as it exists within Visual Studio itself. Other applications should create and expose their own `JoinableTaskContext` and/or `JoinableTaskFactory` for use in code that run in these applications.
38-
See our doc on [consuming `JoinableTaskFactory` from a library](https://github.com/microsoft/vs-threading/blob/main/doc/library_with_jtf.md) for more information.
39-
40-
### Replacing Dispatcher.BeginInvoke
41-
42-
When updating calls to `Dispatcher.BeginInvoke`, there are a few considerations to consider.
43-
44-
1. `BeginInvoke` schedules the delegate for execution later.
45-
1. `BeginInvoke` always executes the delegate on the dispatcher's thread.
46-
1. `BeginInvoke` schedules the delegate at some given priority, or default priority determined by the dispatcher.
47-
48-
To resolve a warning for such code, it is often sufficient to replace it with this, which is *roughly* equivalent:
49-
50-
```cs
51-
await joinableTaskFactory.RunAsync(async delegate {
52-
await joinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
53-
DoSomething();
54-
})
55-
```
56-
57-
The first line in the delegate is necessary to match the behaviors of 1 and 2 on the above list.
58-
When the caller is known to already be on the main thread, you can simplify it slightly to this:
59-
60-
```cs
61-
await joinableTaskFactory.RunAsync(async delegate {
62-
await Task.Yield();
63-
DoSomething();
64-
})
65-
```
66-
67-
Matching behavior 3 on the list above may be important when the dispatcher priority is specified in the BeginInvoke call and was chosen for a particular reason.
68-
In such a case, you can ensure that `JoinableTaskFactory` matches that priority instead of using its default by creating a special `JoinableTaskFactory` instance with the priority setting you require using the [`JoinableTaskFactory.WithPriority`](https://learn.microsoft.com/dotnet/api/microsoft.visualstudio.threading.dispatcherextensions.withpriority?view=visualstudiosdk-2022) method.
69-
70-
Altogether, this might look like:
71-
72-
```cs
73-
await joinableTaskFactory.WithPriority(DispatcherPriority.DataBind).RunAsync(async delegate {
74-
await joinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
75-
DoSomething();
76-
})
77-
```
78-
79-
## Configuration
80-
81-
This analyzer is configurable via the `vs-threading.LegacyThreadSwitchingMembers.txt` file.
82-
See our [configuration](configuration.md) topic for more information.
1+
This content has been moved to [GitHub Pages](https://microsoft.github.io/vs-threading/analyzers/VSTHRD001.html).

doc/analyzers/VSTHRD002.md

+1-45
Original file line numberDiff line numberDiff line change
@@ -1,45 +1 @@
1-
# VSTHRD002 Avoid problematic synchronous waits
2-
3-
Synchronously waiting on `Task`, `ValueTask`, or awaiters is dangerous and may cause dead locks.
4-
5-
## Examples of patterns that are flagged by this analyzer
6-
7-
```csharp
8-
void DoSomething()
9-
{
10-
DoSomethingElseAsync().Wait();
11-
DoSomethingElseAsync().GetAwaiter().GetResult();
12-
var result = CalculateSomethingAsync().Result;
13-
}
14-
```
15-
16-
## Solution
17-
18-
Please consider the following options:
19-
20-
1. Switch to asynchronous wait if the caller is already a "async" method.
21-
1. Change the chain of callers to be "async" methods, and then change this code to be asynchronous await.
22-
1. Use `JoinableTaskFactory.Run()` to wait on the tasks or awaiters.
23-
24-
```csharp
25-
async Task DoSomethingAsync()
26-
{
27-
await DoSomethingElseAsync();
28-
await DoSomethingElseAsync();
29-
var result = await CalculateSomethingAsync();
30-
}
31-
32-
void DoSomething()
33-
{
34-
joinableTaskFactory.Run(async delegate
35-
{
36-
await DoSomethingElseAsync();
37-
await DoSomethingElseAsync();
38-
var result = await CalculateSomethingAsync();
39-
});
40-
}
41-
```
42-
43-
Refer to [Asynchronous and multithreaded programming within VS using the JoinableTaskFactory][1] for more information.
44-
45-
[1]: https://devblogs.microsoft.com/premier-developer/asynchronous-and-multithreaded-programming-within-vs-using-the-joinabletaskfactory/
1+
This content has been moved to [GitHub Pages](https://microsoft.github.io/vs-threading/analyzers/VSTHRD002.html).

0 commit comments

Comments
 (0)