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
- XmlSubtreeReader.cs
- TogglePatternIdentifiers.cs
- MaterialCollection.cs
- ErrorCodes.cs
- ImageClickEventArgs.cs
- ListBoxChrome.cs
- ProgressBarRenderer.cs
- ExternalCalls.cs
- MethodBody.cs
- Path.cs
- RegexInterpreter.cs
- DataGridViewCellLinkedList.cs
- GridView.cs
- DataGridColumn.cs
- WebPartZoneBase.cs
- RemoteWebConfigurationHost.cs
- CurrencyManager.cs
- FacetChecker.cs
- SectionInformation.cs
- TableLayoutStyle.cs
- HandlerMappingMemo.cs
- InputElement.cs
- Guid.cs
- Helpers.cs
- BamlTreeUpdater.cs
- DBSqlParserTable.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- DesignerDataSourceView.cs
- XmlNavigatorStack.cs
- TogglePattern.cs
- CatalogPart.cs
- WorkflowDesignerMessageFilter.cs
- Matrix3DValueSerializer.cs
- SelectionRangeConverter.cs
- EdmRelationshipRoleAttribute.cs
- StylusPointPropertyInfoDefaults.cs
- SessionStateContainer.cs
- CompositeFontFamily.cs
- DataGridViewRowCancelEventArgs.cs
- ListCollectionView.cs
- TabControlCancelEvent.cs
- HtmlTable.cs
- ComboBoxRenderer.cs
- BufferBuilder.cs
- DictionarySurrogate.cs
- RawStylusInputCustomData.cs
- StatusBarPanelClickEvent.cs
- ControlPaint.cs
- shaper.cs
- MachineKey.cs
- Pair.cs
- SharedDp.cs
- WizardPanel.cs
- JsonDeserializer.cs
- RelationshipFixer.cs
- ViewKeyConstraint.cs
- CommandID.cs
- WmfPlaceableFileHeader.cs
- WebPartActionVerb.cs
- CodeDirectoryCompiler.cs
- MemberMaps.cs
- OracleBinary.cs
- ReferenceConverter.cs
- DbProviderConfigurationHandler.cs
- OptimalTextSource.cs
- EncodingNLS.cs
- Utils.cs
- XmlAttribute.cs
- WebPartTracker.cs
- DocumentViewerAutomationPeer.cs
- SQLInt64.cs
- CodeConstructor.cs
- InkPresenter.cs
- BitmapEffectDrawing.cs
- RequestCache.cs
- SerializerWriterEventHandlers.cs
- DbParameterHelper.cs
- Rotation3DAnimation.cs
- SafeReversePInvokeHandle.cs
- DefaultTextStore.cs
- ExpressionBuilderCollection.cs
- Panel.cs
- LinqDataSourceDisposeEventArgs.cs
- InvalidAsynchronousStateException.cs
- StatusBar.cs
- Events.cs
- ExpressionConverter.cs
- BitmapEffectGroup.cs
- XamlStyleSerializer.cs
- InlineCollection.cs
- DragEventArgs.cs
- OptimalBreakSession.cs
- SessionStateSection.cs
- HostProtectionException.cs
- DocumentPage.cs
- DataGridViewRowCancelEventArgs.cs
- ColorInterpolationModeValidation.cs
- SortableBindingList.cs
- DefinitionBase.cs
- HtmlTernaryTree.cs