Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.97 KB

ca2003.md

File metadata and controls

44 lines (33 loc) · 1.97 KB
title description ms.date ms.topic f1_keywords helpviewer_keywords author ms.author manager ms.subservice monikerRange
CA2003: Do not treat fibers as threads
A managed thread is being treated as a Win32 thread.
11/04/2016
reference
CA2003
DoNotTreatFibersAsThreads
CA2003
DoNotTreatFibersAsThreads
mikejo5000
mikejo
mijacobs
code-analysis
vs-2019

CA2003: Do not treat fibers as threads

Item Value
RuleId CA2003
Category Microsoft.Reliability
Breaking change Non-breaking

Cause

A managed thread is being treated as a Win32 thread.

Note

This rule has been deprecated. For more information, see Deprecated rules.

Rule description

Do not assume a managed thread is a Win32 thread; it's a fiber. The common language runtime (CLR) runs managed threads as fibers in the context of real threads that are owned by SQL. These threads can be shared across AppDomains and even databases in the SQL Server process. Using managed thread local storage works, but you might not use unmanaged thread local storage or assume that your code will run on the current OS thread again. Do not change settings such as the locale of the thread. Do not call CreateCriticalSection or CreateMutex via P/Invoke because they require that the thread that enters a lock must also exit the lock. Because the thread that enters a lock doesn't exit a lock when you use fibers, Win32 critical sections and mutexes are useless in SQL. You may safely use most of the state on a managed xref:System.Threading.Thread object, including managed thread local storage and the current user interface (UI) culture of the thread. However, for programming model reasons, you won't be able to change the current culture of a thread when you use SQL. This limitation will be enforced through a new permission.

How to fix violations

Examine your usage of threads and change your code accordingly.

When to suppress warnings

Do not suppress this rule.