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
- MenuBindingsEditorForm.cs
- XmlSchemaSimpleContent.cs
- MailMessage.cs
- ResolveNextArgumentWorkItem.cs
- CultureSpecificCharacterBufferRange.cs
- EncoderReplacementFallback.cs
- TextContainerChangeEventArgs.cs
- COAUTHINFO.cs
- CheckBoxStandardAdapter.cs
- DesignTimeSiteMapProvider.cs
- _SslSessionsCache.cs
- CultureInfoConverter.cs
- Selection.cs
- StackOverflowException.cs
- TextStore.cs
- MarkupExtensionReturnTypeAttribute.cs
- ContentIterators.cs
- Schedule.cs
- RemoteCryptoDecryptRequest.cs
- Component.cs
- EncodingInfo.cs
- Model3DCollection.cs
- MainMenu.cs
- StylusPoint.cs
- FirstQueryOperator.cs
- DataGridHeaderBorder.cs
- EpmTargetPathSegment.cs
- ProxyManager.cs
- WindowsFormsHelpers.cs
- SchemaHelper.cs
- ListViewItemMouseHoverEvent.cs
- ActivityValidator.cs
- ScrollChrome.cs
- FormViewRow.cs
- OleDbErrorCollection.cs
- DataGridView.cs
- DataGridViewCellValidatingEventArgs.cs
- HtmlUtf8RawTextWriter.cs
- WmlCalendarAdapter.cs
- Range.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- SafeHandle.cs
- WSHttpSecurity.cs
- DataTemplateKey.cs
- Animatable.cs
- WebBrowserEvent.cs
- RoutedEventValueSerializer.cs
- Validator.cs
- ExtentKey.cs
- PropertyMapper.cs
- DataGridRowAutomationPeer.cs
- ReachPageContentCollectionSerializer.cs
- SqlConnectionHelper.cs
- ManipulationDevice.cs
- XmlC14NWriter.cs
- HebrewCalendar.cs
- FactoryGenerator.cs
- ClientSettingsStore.cs
- BufferedGraphicsContext.cs
- DefaultTextStore.cs
- OutputWindow.cs
- CacheSection.cs
- RuntimeHandles.cs
- SafeFileMappingHandle.cs
- BrowserCapabilitiesCodeGenerator.cs
- SpinWait.cs
- ELinqQueryState.cs
- ServicePointManager.cs
- StrokeSerializer.cs
- DataControlLinkButton.cs
- ViewStateChangedEventArgs.cs
- IndexObject.cs
- PublisherMembershipCondition.cs
- FormsAuthenticationConfiguration.cs
- TemplateControlParser.cs
- JoinElimination.cs
- EventlogProvider.cs
- ListView.cs
- HttpGetServerProtocol.cs
- TextMarkerSource.cs
- PersonalizableAttribute.cs
- KeyGestureConverter.cs
- DbModificationClause.cs
- ChangesetResponse.cs
- ChildTable.cs
- DrawingCollection.cs
- AsyncResult.cs
- CaseInsensitiveHashCodeProvider.cs
- CompilationLock.cs
- CheckBoxPopupAdapter.cs
- GeneralTransform2DTo3D.cs
- AnnotationHelper.cs
- MSHTMLHost.cs
- SymbolType.cs
- CollectionView.cs
- Collection.cs
- WebPartDeleteVerb.cs
- NameValuePair.cs
- RequestCacheEntry.cs
- ChtmlTextBoxAdapter.cs