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
- TemplateBaseAction.cs
- GridItem.cs
- GridItemPattern.cs
- DesignerOptions.cs
- XmlElementElementCollection.cs
- ElementAction.cs
- CompressStream.cs
- NotifyIcon.cs
- ContextDataSourceView.cs
- WorkflowDesignerMessageFilter.cs
- EFColumnProvider.cs
- ClientScriptManagerWrapper.cs
- GetWinFXPath.cs
- DetailsViewPageEventArgs.cs
- DataTableReaderListener.cs
- OuterGlowBitmapEffect.cs
- SByteConverter.cs
- DataServiceStreamResponse.cs
- SmtpTransport.cs
- AssertFilter.cs
- HttpRawResponse.cs
- ServiceMemoryGates.cs
- Triangle.cs
- FragmentQueryProcessor.cs
- EditorAttributeInfo.cs
- Transform.cs
- TrackingMemoryStream.cs
- MessageEventSubscriptionService.cs
- GraphicsPathIterator.cs
- HttpProfileBase.cs
- WebMessageEncodingBindingElement.cs
- CheckBoxField.cs
- NodeFunctions.cs
- BamlRecordWriter.cs
- FormsIdentity.cs
- GradientSpreadMethodValidation.cs
- XmlReflectionImporter.cs
- DataSourceListEditor.cs
- SequenceNumber.cs
- SuppressIldasmAttribute.cs
- RightsManagementEncryptionTransform.cs
- ChannelSettingsElement.cs
- ArrayTypeMismatchException.cs
- NativeMethods.cs
- MultiBindingExpression.cs
- NullableIntSumAggregationOperator.cs
- _HTTPDateParse.cs
- ToolStripOverflowButton.cs
- KeyEvent.cs
- ParameterCollection.cs
- __ComObject.cs
- ListParaClient.cs
- SoapAttributes.cs
- CookieParameter.cs
- ProvideValueServiceProvider.cs
- Formatter.cs
- PasswordRecovery.cs
- WorkflowTransactionService.cs
- ScrollItemPattern.cs
- BamlResourceDeserializer.cs
- InternalBase.cs
- CombinedGeometry.cs
- DefaultAsyncDataDispatcher.cs
- TextShapeableCharacters.cs
- WindowsServiceCredential.cs
- FullTrustAssembliesSection.cs
- CannotUnloadAppDomainException.cs
- Ray3DHitTestResult.cs
- HttpDictionary.cs
- ConfigXmlElement.cs
- BreakRecordTable.cs
- PropertyGridEditorPart.cs
- TargetException.cs
- Positioning.cs
- _SSPIWrapper.cs
- SqlNotificationEventArgs.cs
- ColorTransform.cs
- MobileControlsSectionHelper.cs
- DescriptionCreator.cs
- Scripts.cs
- SafeFindHandle.cs
- TypefaceCollection.cs
- VirtualDirectoryMapping.cs
- JsonReader.cs
- WindowAutomationPeer.cs
- SqlReorderer.cs
- TextParaClient.cs
- SqlColumnizer.cs
- ThreadAbortException.cs
- VersionedStreamOwner.cs
- CaseCqlBlock.cs
- Calendar.cs
- WorkflowDesigner.cs
- SapiRecognizer.cs
- RequiredAttributeAttribute.cs
- FontUnitConverter.cs
- MbpInfo.cs
- BuildProvider.cs
- Clock.cs
- HuffCodec.cs