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
- SmtpDigestAuthenticationModule.cs
- SqlReorderer.cs
- HttpHandlersSection.cs
- PermissionSet.cs
- StringValidator.cs
- ContentFileHelper.cs
- Mouse.cs
- ReferentialConstraint.cs
- ExpressionNode.cs
- _NestedSingleAsyncResult.cs
- AsnEncodedData.cs
- PersonalizationState.cs
- ActivityValidator.cs
- BamlTreeUpdater.cs
- TypeUsage.cs
- CaretElement.cs
- RawStylusSystemGestureInputReport.cs
- ItemPager.cs
- ToolboxDataAttribute.cs
- PreloadedPackages.cs
- CollectionViewProxy.cs
- RepeaterItemEventArgs.cs
- Number.cs
- BlockUIContainer.cs
- BackgroundFormatInfo.cs
- FunctionDefinition.cs
- DrawingGroup.cs
- MemoryMappedViewStream.cs
- AttachedPropertyDescriptor.cs
- EntityContainerEmitter.cs
- CharAnimationBase.cs
- FactoryGenerator.cs
- UpdatableGenericsFeature.cs
- MD5.cs
- HostSecurityManager.cs
- X509KeyIdentifierClauseType.cs
- CacheChildrenQuery.cs
- DataGridViewBand.cs
- Timer.cs
- SqlDataSourceQueryConverter.cs
- FileLogRecordHeader.cs
- PackageDigitalSignature.cs
- PixelShader.cs
- TypePresenter.xaml.cs
- ResourceBinder.cs
- AttributeCollection.cs
- MailSettingsSection.cs
- AspCompat.cs
- VisualStyleInformation.cs
- ResourceAttributes.cs
- Application.cs
- AlternationConverter.cs
- VirtualPathProvider.cs
- ExternalException.cs
- RemotingSurrogateSelector.cs
- ProxyElement.cs
- ResXBuildProvider.cs
- FileBasedResourceGroveler.cs
- LineProperties.cs
- SqlCacheDependencySection.cs
- TransformedBitmap.cs
- CompensationToken.cs
- KeyEventArgs.cs
- UidPropertyAttribute.cs
- OdbcConnection.cs
- LinearQuaternionKeyFrame.cs
- ActiveDesignSurfaceEvent.cs
- FrugalMap.cs
- TransactionInterop.cs
- IpcServerChannel.cs
- XmlSerializationWriter.cs
- XmlObjectSerializerReadContext.cs
- PinnedBufferMemoryStream.cs
- DebugTracing.cs
- AndCondition.cs
- Accessible.cs
- MenuItemStyle.cs
- Win32MouseDevice.cs
- SchemaComplexType.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- DiscoveryDocumentLinksPattern.cs
- DispatcherProcessingDisabled.cs
- WebPartManagerInternals.cs
- EdmEntityTypeAttribute.cs
- DelayLoadType.cs
- BuildManager.cs
- SafeNativeMethods.cs
- Profiler.cs
- DiffuseMaterial.cs
- EntityDataSourceChangingEventArgs.cs
- WindowsRichEdit.cs
- InternalConfigHost.cs
- SuppressMergeCheckAttribute.cs
- XmlChoiceIdentifierAttribute.cs
- IUnknownConstantAttribute.cs
- DateBoldEvent.cs
- DSASignatureFormatter.cs
- QueryOptionExpression.cs
- RelationshipFixer.cs
- XsltSettings.cs