Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/z-customer-feedback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ body:
label: Type of issue
options:
- Typo
- Code doesn't work
- Code does not work
- Missing information
- Outdated article
- Thank you
- Other (describe below)
validations:
required: true
- type: textarea
id: feedback
validations:
required: true
attributes:
Expand Down
55 changes: 0 additions & 55 deletions .github/policies/close-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,58 +43,3 @@ configuration:
label: code-of-conduct
then:
- closeIssue

- description: Close learn template issues with empty descriptions. (spam)
if:
- payloadType: Issues
- or:
- bodyContains:
pattern: '### Description[\n\r]+\[Enter feedback here\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Escriba sus comentarios aquí\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Tapez vos commentaires ici\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Hier Feedback eingeben\][\n\r]+###'
isRegex: true
- bodyContains:
pattern: '### Description[\n\r]+\[Geri bildiriminizi buraya girin\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Ketikkan umpan balik di sini\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Immetti qui i commenti\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Voer hier feedback in\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Insira comentários aqui\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Введите отзыв здесь\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[اكتب ملاحظاتك هنا\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[在此处输入反馈\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[여기에 피드백 입력\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[フィードバックをこちらに入力してください\][\n\r]+###'
isRegex: True
- bodyContains:
pattern: '### Description[\n\r]+\[Skriv din feedback här\][\n\r]+###'
then:
- addLabel: 'needs-more-info'
- removeLabel: ':watch: Not Triaged'
- addReply:
reply: This issue has been automatically closed due to an empty issue description from the original author. Feel free to reopen it if you have more information that can help us investigate the issue further.
- closeIssue
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ _dependentPackages/
**/.vscode/
.vscode/
!.vscode/extensions.json
*.lscache

# Visual Studio 2019
.vs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The following table shows the list of possible `target` values.
| `module` | Current assembly module |
| `field` | Field in a class or a struct |
| `event` | Event |
| `method` | Method or `get` and `set` property accessors |
| `method` | Method, constructor (including a primary constructor), or `get` and `set` property accessors |
| `param` | Method parameters or `set` property accessor parameters |
| `property` | Property |
| `return` | Return value of a method, property indexer, or `get` property accessor |
Expand Down
3 changes: 3 additions & 0 deletions docs/csharp/language-reference/attributes/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The `AttributeUsage` attribute determines how a custom attribute class can be us
- Module
- Field
- Event
- Constructor
- Method
- Parameter
- Property
Expand Down Expand Up @@ -134,6 +135,8 @@ In this case, `NonInheritedAttribute` isn't applied to `DClass` via inheritance.

You can also use these keywords to specify where an attribute should be applied. For example, you can use the `field:` specifier to add an attribute to the backing field of an [automatically implemented property](../../programming-guide/classes-and-structs/properties.md#automatically-implemented-properties). Or you can use the `field:`, `property:` or `param:` specifier to apply an attribute to any of the elements generated from a positional record. For an example, see [Positional syntax for property definition](../builtin-types/record.md#positional-syntax-for-property-and-field-definition).

When you apply an attribute to a type with a [primary constructor](../../programming-guide/classes-and-structs/instance-constructors.md#primary-constructors), the attribute is applied to the class. You can specify that it's applied to the constructor by choosing the `method` target, which matches the *Constructor* attribute target.

## `AsyncMethodBuilder` attribute

You add the <xref:System.Runtime.CompilerServices.AsyncMethodBuilderAttribute?displayProperty=nameWithType> attribute to a type that can be an async return type. The attribute specifies the type that builds the async method implementation when the specified type is returned from an async method. The `AsyncMethodBuilder` attribute can be applied to a type that:
Expand Down
1 change: 1 addition & 0 deletions docs/csharp/language-reference/tokens/raw-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ The raw string literal's content must not contain a set of contiguous `"` charac
- [C# special characters](./index.md)
- [C# string interpolation](./interpolated.md)
- [String literals (C# language specification)](~/_csharpstandard/standard/lexical-structure.md#6456-string-literals)
- [Raw String literals (C# fundamentals)](../../fundamentals/strings/raw-string-literals.md)
2 changes: 2 additions & 0 deletions docs/standard/threading/managed-threading-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ms.assetid: b2944911-0e8f-427d-a8bb-077550618935

The first five articles of this section are designed to help you determine when to use managed threading and to explain some basic features. For information on classes that provide additional features, see [Threading Objects and Features](threading-objects-and-features.md) and [Overview of Synchronization Primitives](overview-of-synchronization-primitives.md).

> In .NET 9 and C# 13 or later, use a dedicated <xref:System.Threading.Lock?displayProperty=nameWithType> instance with the C# [lock statement](../../csharp/language-reference/statements/lock.md). This approach improves performance and reduces mistakes from locking the wrong object. In Visual Basic, continue to use [SyncLock](../../visual-basic/language-reference/statements/synclock-statement.md) with a dedicated private reference type.

The remaining articles in this section cover advanced topics, including the interaction of managed threading with the Windows operating system.

> [!NOTE]
Expand Down
3 changes: 2 additions & 1 deletion docs/standard/threading/managed-threading-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: "Managed Threading Best Practices"
description: Learn managed threading best practices in .NET. Work with difficult situations such as coordinating many threads or handling blocking threads.
ms.date: 03/13/2026
ai-usage: ai-assisted
dev_langs:
- "csharp"
- "vb"
Expand Down Expand Up @@ -95,6 +94,8 @@ Consider the following guidelines when using multiple threads:

- Use caution when locking on instances, for example `lock(this)` in C# or `SyncLock(Me)` in Visual Basic. If other code in your application, external to the type, takes a lock on the object, deadlocks could occur.

- In .NET 9 and C# 13 or later, use a dedicated <xref:System.Threading.Lock?displayProperty=nameWithType> instance as your lock object with the C# [lock statement](../../csharp/language-reference/statements/lock.md). In Visual Basic, continue to use a dedicated private reference type instance with `SyncLock`.

- Do ensure that a thread that has entered a monitor always leaves that monitor, even if an exception occurs while the thread is in the monitor. The C# [lock](../../csharp/language-reference/statements/lock.md) statement and the Visual Basic [SyncLock](../../visual-basic/language-reference/statements/synclock-statement.md) statement provide this behavior automatically, employing a **finally** block to ensure that <xref:System.Threading.Monitor.Exit*?displayProperty=nameWithType> is called. If you cannot ensure that **Exit** will be called, consider changing your design to use **Mutex**. A mutex is automatically released when the thread that currently owns it terminates.

- Do use multiple threads for tasks that require different resources, and avoid assigning multiple threads to a single resource. For example, any task involving I/O benefits from having its own thread, because that thread will block during I/O operations and thus allow other threads to execute. User input is another resource that benefits from a dedicated thread. On a single-processor computer, a task that involves intensive computation coexists with user input and with tasks that involve I/O, but multiple computation-intensive tasks contend with each other.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ You can coordinate the interaction of threads that acquire a lock on the same ob
For more information, see the <xref:System.Threading.Monitor> API reference.

> [!NOTE]
> Use the [lock](../../csharp/language-reference/statements/lock.md) statement in C# and the [SyncLock](../../visual-basic/language-reference/statements/synclock-statement.md) statement in Visual Basic to synchronize access to a shared resource instead of using the <xref:System.Threading.Monitor> class directly. Those statements are implemented by using the <xref:System.Threading.Monitor.Enter*> and <xref:System.Threading.Monitor.Exit*> methods and a `try…finally` block to ensure that the acquired lock is always released.
> To synchronize access to a shared resource, use the [lock](../../csharp/language-reference/statements/lock.md) statement in C# and the [SyncLock](../../visual-basic/language-reference/statements/synclock-statement.md) statement in Visual Basic instead of using the <xref:System.Threading.Monitor> class directly.
>
> In .NET 9 and C# 13 or later, use a dedicated <xref:System.Threading.Lock?displayProperty=nameWithType> instance for best performance. In that case, `lock` uses <xref:System.Threading.Lock.EnterScope?displayProperty=nameWithType>.
>
> This approach is better than locking a general `object` because it uses a lock type designed for synchronization and reduces accidental reuse of unrelated objects.
>
> Visual Basic doesn't support `System.Threading.Lock` in `SyncLock`, so use a dedicated private reference type for `SyncLock`. For C# versions before 13, .NET versions before 9, and Visual Basic, these statements use <xref:System.Threading.Monitor.Enter*> and <xref:System.Threading.Monitor.Exit*> with a `try…finally` block to ensure that the acquired lock is always released.

### Mutex class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ When multiple threads can make calls to the properties and methods of a single o
Both Visual Basic and C# support the marking of blocks of code with a particular language keyword, the `lock` statement in C# or the `SyncLock` statement in Visual Basic. When the code is executed by a thread, an attempt is made to acquire the lock. If the lock has already been acquired by another thread, the thread blocks until the lock becomes available. When the thread exits the synchronized block of code, the lock is released, no matter how the thread exits the block.

> [!NOTE]
> Beginning in C# 13, the `lock` statement recognizes if the locked object is an instance of <xref:System.Threading.Lock?displayProperty=nameWithType> and uses the `EnterScope` method to create a synchronized region. The `lock`, when the target isn't a `Lock` instance, and `SyncLock` statements are implemented using <xref:System.Threading.Monitor.Enter*?displayProperty=nameWithType> and <xref:System.Threading.Monitor.Exit*?displayProperty=nameWithType>, so other methods of <xref:System.Threading.Monitor> can be used in conjunction with them within the synchronized region.
> In .NET 9 and C# 13 or later, if the `lock` target is a dedicated <xref:System.Threading.Lock?displayProperty=nameWithType> instance, the `lock` statement uses <xref:System.Threading.Lock.EnterScope?displayProperty=nameWithType> to create a synchronized region.
>
> Visual Basic doesn't support `System.Threading.Lock` in `SyncLock`, so continue to use `SyncLock` with a dedicated private reference type.
>
> If the `lock` target isn't a `Lock` instance, and for all `SyncLock` usage, the compiler uses <xref:System.Threading.Monitor.Enter*?displayProperty=nameWithType> and <xref:System.Threading.Monitor.Exit*?displayProperty=nameWithType>. Because of that implementation, you can still use other <xref:System.Threading.Monitor> methods in the synchronized region.

You can also decorate a method with a <xref:System.Runtime.CompilerServices.MethodImplAttribute> with a value of <xref:System.Runtime.CompilerServices.MethodImplOptions.Synchronized?displayProperty=nameWithType>, which has the same effect as using <xref:System.Threading.Monitor> or one of the compiler keywords to lock the entire body of the method.

Expand Down
3 changes: 3 additions & 0 deletions docs/standard/threading/threading-objects-and-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Along with the <xref:System.Threading.Thread?displayProperty=nameWithType> class
|[SpinLock](spinlock.md)|Describes the <xref:System.Threading.SpinLock?displayProperty=nameWithType> structure, which is a lightweight alternative to the <xref:System.Threading.Monitor?displayProperty=nameWithType> class for certain low-level locking scenarios.|
|[SpinWait](spinwait.md)|Describes the <xref:System.Threading.SpinWait?displayProperty=nameWithType> structure, which provides support for spin-based waiting.|

> [!NOTE]
> In .NET 9 and C# 13 or later, prefer a dedicated <xref:System.Threading.Lock?displayProperty=nameWithType> instance with the C# `lock` statement for general locking scenarios. This approach improves performance and reduces mistakes from locking shared objects that weren't meant for synchronization. For details, see [Overview of synchronization primitives](overview-of-synchronization-primitives.md) and [The lock statement](../../csharp/language-reference/statements/lock.md). In Visual Basic, continue to use `SyncLock` with a dedicated private reference type.

## See also

- <xref:System.Threading.Monitor?displayProperty=nameWithType>
Expand Down
Loading