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
- DelayedRegex.cs
- ProgressChangedEventArgs.cs
- ClusterRegistryConfigurationProvider.cs
- BindingValueChangedEventArgs.cs
- OverflowException.cs
- DocumentPage.cs
- SerializationBinder.cs
- AddInBase.cs
- TextEditorSelection.cs
- Matrix3DValueSerializer.cs
- DocumentSequence.cs
- ResolveRequestResponseAsyncResult.cs
- TextEncodedRawTextWriter.cs
- ListBase.cs
- LayoutManager.cs
- ITreeGenerator.cs
- XamlSerializerUtil.cs
- CodeObject.cs
- TimeZone.cs
- SQLStringStorage.cs
- InternalBufferManager.cs
- XsdDataContractExporter.cs
- SystemPens.cs
- DecimalAnimationBase.cs
- ConfigUtil.cs
- SlotInfo.cs
- RectangleConverter.cs
- linebase.cs
- Panel.cs
- CompositionAdorner.cs
- ArgumentNullException.cs
- SqlConnection.cs
- OdbcError.cs
- ListenerElementsCollection.cs
- RegistrySecurity.cs
- RuleAttributes.cs
- UrlAuthFailedErrorFormatter.cs
- ValidatorCompatibilityHelper.cs
- PrimaryKeyTypeConverter.cs
- SignatureToken.cs
- HwndSourceKeyboardInputSite.cs
- AssemblyGen.cs
- PageRanges.cs
- DataGridState.cs
- RangeBase.cs
- XmlHelper.cs
- InvalidWMPVersionException.cs
- GlyphTypeface.cs
- HuffCodec.cs
- Math.cs
- FileStream.cs
- TextEncodedRawTextWriter.cs
- COM2Properties.cs
- TextContainerChangedEventArgs.cs
- HMACSHA1.cs
- XmlAutoDetectWriter.cs
- ShaderRenderModeValidation.cs
- Char.cs
- InkCanvas.cs
- PersonalizableAttribute.cs
- DataRecordInternal.cs
- DefaultPrintController.cs
- DispatcherExceptionEventArgs.cs
- UpdatePanelTriggerCollection.cs
- ProcessThreadCollection.cs
- HotSpotCollection.cs
- shaperfactoryquerycacheentry.cs
- XPathCompiler.cs
- ExtensionWindowHeader.cs
- IODescriptionAttribute.cs
- tooltip.cs
- ListControl.cs
- ItemCheckedEvent.cs
- DrawingState.cs
- CharacterBufferReference.cs
- OracleFactory.cs
- ExpandSegmentCollection.cs
- SchemaCollectionCompiler.cs
- DataGridTable.cs
- XComponentModel.cs
- WSSecurityOneDotZeroSendSecurityHeader.cs
- InstanceValue.cs
- MessageLoggingElement.cs
- SoundPlayer.cs
- UserMapPath.cs
- RichTextBox.cs
- mediapermission.cs
- AuthenticateEventArgs.cs
- XPathDocumentIterator.cs
- _LoggingObject.cs
- WSHttpSecurity.cs
- AccessedThroughPropertyAttribute.cs
- COM2ColorConverter.cs
- SynchronizingStream.cs
- ChannelManager.cs
- OleDbPermission.cs
- NavigatorOutput.cs
- RetrieveVirtualItemEventArgs.cs
- GestureRecognizer.cs
- GridViewDeleteEventArgs.cs