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
- IdentityModelDictionary.cs
- DataPagerCommandEventArgs.cs
- ProjectionPathBuilder.cs
- EntityConnectionStringBuilderItem.cs
- ProxyWebPartManagerDesigner.cs
- FtpCachePolicyElement.cs
- ControlBuilder.cs
- TableItemPatternIdentifiers.cs
- GenericXmlSecurityToken.cs
- ContentElement.cs
- ContainerCodeDomSerializer.cs
- SafeFileMappingHandle.cs
- Merger.cs
- ArgumentsParser.cs
- MulticastOption.cs
- WeakRefEnumerator.cs
- XmlSerializerFactory.cs
- WebReferencesBuildProvider.cs
- CorePropertiesFilter.cs
- TemplateBindingExpressionConverter.cs
- SafeViewOfFileHandle.cs
- ScrollChrome.cs
- DataBindingCollectionEditor.cs
- Rules.cs
- EnumValidator.cs
- DataGridRowsPresenter.cs
- XPathDocument.cs
- ObjectContext.cs
- AppDomain.cs
- FixedSOMSemanticBox.cs
- DataGridViewColumnTypePicker.cs
- ResourcePart.cs
- Grid.cs
- Sql8ConformanceChecker.cs
- LabelLiteral.cs
- DesignBindingEditor.cs
- HttpListener.cs
- Image.cs
- CalendarTable.cs
- BackStopAuthenticationModule.cs
- ConfigurationException.cs
- IntSecurity.cs
- StreamResourceInfo.cs
- ProfileModule.cs
- LinkClickEvent.cs
- SqlAliasesReferenced.cs
- Variant.cs
- DataGridCaption.cs
- OdbcCommand.cs
- GetPageNumberCompletedEventArgs.cs
- SessionStateModule.cs
- ModulesEntry.cs
- Globals.cs
- EmptyElement.cs
- ConditionalDesigner.cs
- ConfigLoader.cs
- CachedPathData.cs
- DependencyObjectProvider.cs
- SizeF.cs
- AddDataControlFieldDialog.cs
- ListViewEditEventArgs.cs
- XslNumber.cs
- StatusBar.cs
- DiscoveryRequestHandler.cs
- ActivityCodeGenerator.cs
- TagPrefixAttribute.cs
- BindableTemplateBuilder.cs
- UpdateRecord.cs
- XmlIncludeAttribute.cs
- EncryptedData.cs
- GraphicsContext.cs
- OutKeywords.cs
- TransportSecurityBindingElement.cs
- SecurityUniqueId.cs
- PreProcessInputEventArgs.cs
- StringAnimationUsingKeyFrames.cs
- ConfigurationLockCollection.cs
- ExceptionHelpers.cs
- SqlConnectionHelper.cs
- MailMessage.cs
- SchemaImporterExtensionElement.cs
- Timeline.cs
- SingleAnimationBase.cs
- CodeDesigner.cs
- shaperfactory.cs
- xmlsaver.cs
- TimelineCollection.cs
- PointLight.cs
- RoleGroup.cs
- TextBoxBase.cs
- BoundingRectTracker.cs
- Color.cs
- ItemCheckEvent.cs
- AmbientProperties.cs
- PenLineCapValidation.cs
- SecondaryViewProvider.cs
- DataObjectPastingEventArgs.cs
- WpfXamlLoader.cs
- XmlUtil.cs
- IndexOutOfRangeException.cs