Code running within the Visual Studio process (and primary AppDomain)
should avoid creating a new instance of JoinableTaskContext
,
as doing so may introduce deadlocks. Instead, everyone should share the
JoinableTaskContext
instance offered by ThreadHelper.JoinableTaskContext
.
This analyzer may be turned off for unit test projects, which may have a legitimate need to create a JoinableTaskContext.
class MyCoolPackage : Package
{
void Foo()
{
var jtc = new JoinableTaskContext(); // this line flagged
}
}
Use the JoinableTaskContext
available from the ThreadHelper
class.
class MyCoolPackage : Package
{
void Foo()
{
var jtc = ThreadHelper.JoinableTaskContext;
}
}