You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@ -10,12 +10,16 @@ namespace System.ServiceModel
|
||||
|
||||
public sealed class OperationContextScope : IDisposable
|
||||
{
|
||||
[ThreadStatic]
|
||||
static OperationContextScope legacyCurrentScope;
|
||||
|
||||
static AsyncLocal<OperationContextScope> currentScope = new AsyncLocal<OperationContextScope>();
|
||||
|
||||
OperationContext currentContext;
|
||||
bool disposed;
|
||||
readonly OperationContext originalContext = OperationContext.Current;
|
||||
readonly OperationContextScope originalScope = OperationContextScope.currentScope.Value;
|
||||
readonly OperationContextScope originalScope = OperationContextScope.CurrentScope;
|
||||
readonly Thread thread = Thread.CurrentThread;
|
||||
|
||||
public OperationContextScope(IContextChannel channel)
|
||||
{
|
||||
@ -27,6 +31,26 @@ namespace System.ServiceModel
|
||||
this.PushContext(context);
|
||||
}
|
||||
|
||||
private static OperationContextScope CurrentScope
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceModelAppSettings.DisableOperationContextAsyncFlow ? legacyCurrentScope : currentScope.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (ServiceModelAppSettings.DisableOperationContextAsyncFlow)
|
||||
{
|
||||
legacyCurrentScope = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentScope.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!this.disposed)
|
||||
@ -38,20 +62,31 @@ namespace System.ServiceModel
|
||||
|
||||
void PushContext(OperationContext context)
|
||||
{
|
||||
bool isAsyncFlowEnabled = OperationContext.ShouldUseAsyncLocalContext;
|
||||
|
||||
this.currentContext = context;
|
||||
OperationContextScope.currentScope.Value = this;
|
||||
|
||||
if (isAsyncFlowEnabled)
|
||||
{
|
||||
OperationContext.EnableAsyncFlow(this.currentContext);
|
||||
}
|
||||
|
||||
CurrentScope = this;
|
||||
OperationContext.Current = this.currentContext;
|
||||
}
|
||||
|
||||
void PopContext()
|
||||
{
|
||||
if (OperationContextScope.currentScope.Value != this)
|
||||
if (ServiceModelAppSettings.DisableOperationContextAsyncFlow && this.thread != Thread.CurrentThread)
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInvalidContextScopeThread0)));
|
||||
|
||||
if (CurrentScope != this)
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInterleavedContextScopes0)));
|
||||
|
||||
if (OperationContext.Current != this.currentContext)
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxContextModifiedInsideScope0)));
|
||||
|
||||
OperationContextScope.currentScope.Value = this.originalScope;
|
||||
CurrentScope = this.originalScope;
|
||||
OperationContext.Current = this.originalContext;
|
||||
|
||||
if (this.currentContext != null)
|
||||
|
Reference in New Issue
Block a user