Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities.DurableInstancing / System / Activities / DurableInstancing / SqlWorkflowInstanceStoreLock.cs / 1305376 / SqlWorkflowInstanceStoreLock.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.DurableInstancing { using System; using System.Collections.Generic; using System.Linq; using System.Runtime; using System.Runtime.DurableInstancing; using System.Threading; class SqlWorkflowInstanceStoreLock { bool isBeingModified; Guid lockOwnerId; SqlWorkflowInstanceStore sqlWorkflowInstanceStore; WeakReference lockOwnerInstanceHandle; object thisLock; public SqlWorkflowInstanceStoreLock(SqlWorkflowInstanceStore sqlWorkflowInstanceStore) { this.sqlWorkflowInstanceStore = sqlWorkflowInstanceStore; this.thisLock = new object(); this.SurrogateLockOwnerId = -1; } public PersistenceTask InstanceDetectionTask { get; set; } public bool IsValid { get { return IsLockOwnerValid(this.SurrogateLockOwnerId); } } public bool IsLockOwnerValid(long surrogateLockOwnerId) { return (this.SurrogateLockOwnerId != -1) && (surrogateLockOwnerId == this.SurrogateLockOwnerId) && (this.sqlWorkflowInstanceStore.InstanceOwnersExist); } public Guid LockOwnerId { get { return this.lockOwnerId; } } public PersistenceTask LockRecoveryTask { get; set; } public PersistenceTask LockRenewalTask { get; set; } public long SurrogateLockOwnerId { get; private set; } object ThisLock { get { return this.thisLock; } } public void MarkInstanceOwnerCreated(Guid lockOwnerId, long surrogateLockOwnerId, InstanceHandle lockOwnerInstanceHandle, bool detectRunnableInstances, bool detectActivatableInstances) { Fx.Assert(this.isBeingModified, "Must have modification lock to mark owner as created"); this.lockOwnerId = lockOwnerId; this.SurrogateLockOwnerId = surrogateLockOwnerId; this.lockOwnerInstanceHandle = new WeakReference(lockOwnerInstanceHandle); TimeSpan hostLockRenewalPeriod = this.sqlWorkflowInstanceStore.HostLockRenewalPeriod; TimeSpan runnableInstancesDetectionPeriod = this.sqlWorkflowInstanceStore.RunnableInstancesDetectionPeriod; if (detectActivatableInstances) { this.InstanceDetectionTask = new DetectActivatableWorkflowsTask(this.sqlWorkflowInstanceStore, this, runnableInstancesDetectionPeriod); } else if (detectRunnableInstances) { this.InstanceDetectionTask = new DetectRunnableInstancesTask(this.sqlWorkflowInstanceStore, this, runnableInstancesDetectionPeriod); } this.LockRenewalTask = new LockRenewalTask(this.sqlWorkflowInstanceStore, this, hostLockRenewalPeriod); this.LockRecoveryTask = new LockRecoveryTask(this.sqlWorkflowInstanceStore, this, hostLockRenewalPeriod); if (this.InstanceDetectionTask != null) { this.InstanceDetectionTask.ResetTimer(true); } this.LockRenewalTask.ResetTimer(true); this.LockRecoveryTask.ResetTimer(true); } public void MarkInstanceOwnerLost(long surrogateLockOwnerId, bool hasModificationLock) { if (hasModificationLock) { this.MarkInstanceOwnerLost(surrogateLockOwnerId); } else { this.TakeModificationLock(); this.MarkInstanceOwnerLost(surrogateLockOwnerId); this.ReturnModificationLock(); } } public void ReturnModificationLock() { Fx.Assert(this.isBeingModified, "Must have modification lock to release it!"); bool lockTaken = false; while (true) { Monitor.Enter(ThisLock, ref lockTaken); if (lockTaken) { this.isBeingModified = false; Monitor.Pulse(ThisLock); Monitor.Exit(ThisLock); return; } } } public void TakeModificationLock() { bool lockTaken = false; while (true) { Monitor.Enter(ThisLock, ref lockTaken); if (lockTaken) { while (this.isBeingModified) { Monitor.Wait(ThisLock); } this.isBeingModified = true; Monitor.Exit(ThisLock); return; } } } void MarkInstanceOwnerLost(long surrogateLockOwnerId) { Fx.Assert(this.isBeingModified, "Must have modification lock to mark owner as lost"); if (this.SurrogateLockOwnerId == surrogateLockOwnerId) { this.SurrogateLockOwnerId = -1; InstanceHandle instanceHandle = this.lockOwnerInstanceHandle.Target as InstanceHandle; if (instanceHandle != null) { instanceHandle.Free(); } if (this.sqlWorkflowInstanceStore.IsLockRetryEnabled()) { this.sqlWorkflowInstanceStore.LoadRetryHandler.AbortPendingRetries(); } if (this.LockRenewalTask != null) { this.LockRenewalTask.CancelTimer(); } if (this.LockRecoveryTask != null) { this.LockRecoveryTask.CancelTimer(); } if (this.InstanceDetectionTask != null) { this.InstanceDetectionTask.CancelTimer(); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HashCoreRequest.cs
- TemplateKeyConverter.cs
- DesignTimeXamlWriter.cs
- mediaeventshelper.cs
- CompilerError.cs
- CompoundFileReference.cs
- ProtocolsConfigurationEntry.cs
- QueryCacheManager.cs
- _HeaderInfoTable.cs
- SystemIPInterfaceProperties.cs
- EntityDataSourceWizardForm.cs
- OracleColumn.cs
- basecomparevalidator.cs
- WorkflowHostingResponseContext.cs
- GenericWebPart.cs
- Function.cs
- Transactions.cs
- WindowsUpDown.cs
- QueryableFilterRepeater.cs
- AudioDeviceOut.cs
- ObjectDataSourceDisposingEventArgs.cs
- MessageRpc.cs
- FontFamilyIdentifier.cs
- DatagridviewDisplayedBandsData.cs
- FullTextState.cs
- DesignerPerfEventProvider.cs
- TemplatedAdorner.cs
- SchemaTypeEmitter.cs
- WebConfigurationManager.cs
- control.ime.cs
- ContentTextAutomationPeer.cs
- ValidatedMobileControlConverter.cs
- FixedSOMPageConstructor.cs
- SolidBrush.cs
- XmlIgnoreAttribute.cs
- AccessedThroughPropertyAttribute.cs
- SQLMoneyStorage.cs
- DeferredSelectedIndexReference.cs
- ClientProxyGenerator.cs
- SharedUtils.cs
- TransactionalPackage.cs
- XhtmlBasicCalendarAdapter.cs
- SoapExtensionTypeElement.cs
- IsolatedStorageFilePermission.cs
- WeakReferenceKey.cs
- NetMsmqBindingElement.cs
- SerializationInfo.cs
- XmlEventCache.cs
- StylusPointPropertyInfo.cs
- SrgsRuleRef.cs
- Stackframe.cs
- AsymmetricSignatureDeformatter.cs
- HttpInputStream.cs
- TextEndOfParagraph.cs
- ListSourceHelper.cs
- HttpVersion.cs
- Collection.cs
- MissingMemberException.cs
- XsdDataContractImporter.cs
- StylusCaptureWithinProperty.cs
- Command.cs
- Token.cs
- XPathParser.cs
- TextEffectCollection.cs
- RSAPKCS1SignatureFormatter.cs
- DrawingCollection.cs
- DataSetMappper.cs
- PeerNameResolver.cs
- ExpandCollapseProviderWrapper.cs
- ConstraintCollection.cs
- TextEndOfLine.cs
- ImageListStreamer.cs
- FamilyTypefaceCollection.cs
- EllipticalNodeOperations.cs
- WebPartCatalogCloseVerb.cs
- SQLStringStorage.cs
- JoinGraph.cs
- ContainerFilterService.cs
- DrawingBrush.cs
- Control.cs
- WriteTimeStream.cs
- SoapInteropTypes.cs
- OutputScopeManager.cs
- ConfigurationProperty.cs
- RichTextBox.cs
- CodePageEncoding.cs
- UIElementParagraph.cs
- Baml6Assembly.cs
- OutputCacheSection.cs
- IncrementalCompileAnalyzer.cs
- GifBitmapDecoder.cs
- GestureRecognitionResult.cs
- VisualTreeHelper.cs
- DirectoryNotFoundException.cs
- Color.cs
- CodeAttributeArgumentCollection.cs
- Opcode.cs
- WebPartConnectionCollection.cs
- BrowserCapabilitiesFactoryBase.cs
- SpotLight.cs