Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / ThreadBehavior.cs / 1 / ThreadBehavior.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{
using System;
using System.ServiceModel;
using System.Threading;
using System.ServiceModel.Channels;
class ThreadBehavior
{
SendOrPostCallback threadAffinityCallback;
static WaitCallback cleanThreadCallback;
readonly SynchronizationContext context;
internal ThreadBehavior(DispatchRuntime dispatch)
{
this.context = dispatch.SynchronizationContext;
}
SendOrPostCallback ThreadAffinityCallbackDelegate
{
get
{
if (this.threadAffinityCallback == null)
{
this.threadAffinityCallback = new SendOrPostCallback(this.SynchronizationContextCallback);
}
return this.threadAffinityCallback;
}
}
static WaitCallback CleanThreadCallbackDelegate
{
get
{
if (ThreadBehavior.cleanThreadCallback == null)
{
ThreadBehavior.cleanThreadCallback = new WaitCallback(ThreadBehavior.CleanThreadCallback);
}
return ThreadBehavior.cleanThreadCallback;
}
}
internal void BindThread(ref MessageRpc rpc)
{
SynchronizationContext context = rpc.InstanceContext.SynchronizationContext ?? this.context;
if (context != null)
{
IResumeMessageRpc resume = rpc.Pause();
context.Post(this.ThreadAffinityCallbackDelegate, resume);
}
else if (rpc.SwitchedThreads)
{
IResumeMessageRpc resume = rpc.Pause();
IOThreadScheduler.ScheduleCallback(ThreadBehavior.CleanThreadCallbackDelegate, resume);
}
}
internal void BindEndThread(ref MessageRpc rpc)
{
this.BindThread(ref rpc);
}
void SynchronizationContextCallback(object state)
{
bool alreadyResumedNoLock;
((IResumeMessageRpc)state).Resume(out alreadyResumedNoLock);
if (alreadyResumedNoLock)
{
string text = SR.GetString(SR.SFxMultipleCallbackFromSynchronizationContext, context.GetType().ToString());
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(text));
}
}
static void CleanThreadCallback(object state)
{
bool alreadyResumedNoLock;
((IResumeMessageRpc)state).Resume(out alreadyResumedNoLock);
if (alreadyResumedNoLock)
{
DiagnosticUtility.DebugAssert("IOThreadScheduler called back twice");
}
}
internal static SynchronizationContext GetCurrentSynchronizationContext()
{
if (ServiceHostingEnvironment.ApplicationDomainHosted)
{
return null;
}
return SynchronizationContext.Current;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ByteAnimation.cs
- XmlSchemaImport.cs
- LockedAssemblyCache.cs
- sitestring.cs
- DBConcurrencyException.cs
- UIElementCollection.cs
- Message.cs
- RichTextBoxAutomationPeer.cs
- SafeProcessHandle.cs
- HttpWebRequestElement.cs
- EventWaitHandle.cs
- BrowserTree.cs
- EditingScopeUndoUnit.cs
- CircleHotSpot.cs
- MenuItem.cs
- _NTAuthentication.cs
- ClientRolePrincipal.cs
- DataControlFieldsEditor.cs
- DataObjectEventArgs.cs
- BinaryUtilClasses.cs
- NativeMethods.cs
- SelectionEditor.cs
- ListViewItem.cs
- Style.cs
- MemberProjectedSlot.cs
- SafeThemeHandle.cs
- OdbcConnectionStringbuilder.cs
- securestring.cs
- _UncName.cs
- BuildProviderUtils.cs
- BookmarkNameHelper.cs
- WindowsEditBoxRange.cs
- GeometryHitTestParameters.cs
- ReadOnlyCollectionBase.cs
- TextProperties.cs
- Rijndael.cs
- ToolStripSeparator.cs
- CheckBox.cs
- FormParameter.cs
- ManipulationInertiaStartingEventArgs.cs
- InfoCardTraceRecord.cs
- EntityContainerEmitter.cs
- ApplicationActivator.cs
- ActivityTypeResolver.xaml.cs
- TimeStampChecker.cs
- PropertyValueUIItem.cs
- loginstatus.cs
- PackageFilter.cs
- HtmlAnchor.cs
- StreamGeometryContext.cs
- DataGridRowAutomationPeer.cs
- StorageMappingFragment.cs
- InvalidateEvent.cs
- OperationCanceledException.cs
- ListControlDesigner.cs
- MSAAWinEventWrap.cs
- xml.cs
- ReferentialConstraint.cs
- DateBoldEvent.cs
- SQLDateTimeStorage.cs
- KnowledgeBase.cs
- ManipulationStartedEventArgs.cs
- Formatter.cs
- AuthenticatingEventArgs.cs
- DotExpr.cs
- NegotiateStream.cs
- SubMenuStyleCollection.cs
- RuleInfoComparer.cs
- ProfileProvider.cs
- RealizedColumnsBlock.cs
- ConstNode.cs
- MatrixKeyFrameCollection.cs
- EffectiveValueEntry.cs
- StrokeCollectionDefaultValueFactory.cs
- SettingsPropertyWrongTypeException.cs
- HelpKeywordAttribute.cs
- PageSetupDialog.cs
- ViewPort3D.cs
- Menu.cs
- ZipIOBlockManager.cs
- Object.cs
- FlowDocumentView.cs
- List.cs
- ContactManager.cs
- RecipientInfo.cs
- EndOfStreamException.cs
- MemoryStream.cs
- PowerStatus.cs
- XmlProcessingInstruction.cs
- ClientTargetSection.cs
- InfoCardCryptoHelper.cs
- DesignTimeXamlWriter.cs
- EditorPartChrome.cs
- InstancePersistenceEvent.cs
- StackSpiller.Generated.cs
- PersonalizationEntry.cs
- TraceFilter.cs
- CompiledRegexRunnerFactory.cs
- HttpCachePolicyElement.cs
- BlurBitmapEffect.cs