Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / CancellationScope.cs / 1305376 / CancellationScope.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Statements { using System; using System.Activities; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.Collections; using System.Windows.Markup; [ContentProperty("Body")] public sealed class CancellationScope : NativeActivity { Collectionvariables; Variable suppressCancel; public CancellationScope() : base() { this.suppressCancel = new Variable (); } public Collection Variables { get { if (this.variables == null) { this.variables = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } } }; } return this.variables; } } [DefaultValue(null)] [DependsOn("Variables")] public Activity Body { get; set; } [DefaultValue(null)] [DependsOn("Body")] public Activity CancellationHandler { get; set; } protected override void CacheMetadata(NativeActivityMetadata metadata) { metadata.AddChild(this.Body); metadata.AddChild(this.CancellationHandler); metadata.SetVariablesCollection(this.Variables); metadata.AddImplementationVariable(this.suppressCancel); } protected override void Execute(NativeActivityContext context) { if (this.Body != null) { context.ScheduleActivity(this.Body, new CompletionCallback(OnBodyComplete)); } } void OnBodyComplete(NativeActivityContext context, ActivityInstance completedInstance) { // Determine whether to run the Cancel based on whether the body // canceled rather than whether cancel had been requested. if (completedInstance.State == ActivityInstanceState.Canceled || (context.IsCancellationRequested && completedInstance.State == ActivityInstanceState.Faulted)) { // We don't cancel the cancel handler this.suppressCancel.Set(context, true); context.MarkCanceled(); if (this.CancellationHandler != null) { context.ScheduleActivity(this.CancellationHandler, onFaulted : new FaultCallback(OnExceptionFromCancelHandler)); } } } protected override void Cancel(NativeActivityContext context) { bool suppressCancel = this.suppressCancel.Get(context); if (!suppressCancel) { context.CancelChildren(); } } void OnExceptionFromCancelHandler(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom) { this.suppressCancel.Set(context, false); } } } // 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
- XamlSerializerUtil.cs
- RuntimeHelpers.cs
- FormatSettings.cs
- ButtonChrome.cs
- Typography.cs
- IApplicationTrustManager.cs
- ISAPIRuntime.cs
- HtmlTableCell.cs
- QuaternionAnimationBase.cs
- RowSpanVector.cs
- AnnotationAuthorChangedEventArgs.cs
- UTF8Encoding.cs
- DictionarySectionHandler.cs
- RichTextBox.cs
- NotConverter.cs
- XmlWhitespace.cs
- CompletionCallbackWrapper.cs
- MatrixTransform.cs
- TextElement.cs
- UserControlCodeDomTreeGenerator.cs
- DBSqlParserTableCollection.cs
- RuleSettingsCollection.cs
- InputScopeNameConverter.cs
- SqlTriggerContext.cs
- CompositeCollectionView.cs
- WorkflowPersistenceContext.cs
- SqlDelegatedTransaction.cs
- DocumentPageHost.cs
- Font.cs
- RotateTransform3D.cs
- ObjectListItem.cs
- FreezableDefaultValueFactory.cs
- BasicExpandProvider.cs
- OpCellTreeNode.cs
- RoleServiceManager.cs
- CredentialCache.cs
- RowTypePropertyElement.cs
- ServicePerformanceCounters.cs
- Translator.cs
- DiagnosticTraceSchemas.cs
- HeaderUtility.cs
- SafeFileMappingHandle.cs
- SQLSingleStorage.cs
- KeyedHashAlgorithm.cs
- StateManagedCollection.cs
- MetadataItemEmitter.cs
- FontCacheUtil.cs
- Listbox.cs
- Binding.cs
- UInt16.cs
- Tablet.cs
- ObjectItemCollection.cs
- RtfControls.cs
- ConfigErrorGlyph.cs
- Mappings.cs
- HashAlgorithm.cs
- SqlCommandSet.cs
- SqlBinder.cs
- CodeArrayCreateExpression.cs
- VirtualPathUtility.cs
- ComponentDispatcherThread.cs
- DataGridViewTextBoxEditingControl.cs
- FixedPosition.cs
- _ProxyChain.cs
- Stack.cs
- SqlDependencyListener.cs
- FileNotFoundException.cs
- EventLogEntry.cs
- TreeNodeClickEventArgs.cs
- _FixedSizeReader.cs
- Effect.cs
- TraceHwndHost.cs
- FontFamilyConverter.cs
- FormCollection.cs
- RMPublishingDialog.cs
- InputScopeConverter.cs
- KeyboardDevice.cs
- SqlCharStream.cs
- HttpListenerPrefixCollection.cs
- CaseCqlBlock.cs
- IntegrationExceptionEventArgs.cs
- ExpressionBindingsDialog.cs
- FrameSecurityDescriptor.cs
- FlowDecisionLabelFeature.cs
- DescendentsWalkerBase.cs
- MtomMessageEncodingBindingElement.cs
- FreezableDefaultValueFactory.cs
- OleDbReferenceCollection.cs
- WeakReferenceList.cs
- WindowsListViewItemStartMenu.cs
- Msmq3PoisonHandler.cs
- RewritingSimplifier.cs
- CommandID.cs
- ShaderEffect.cs
- MenuItem.cs
- ZipIOModeEnforcingStream.cs
- XmlILConstructAnalyzer.cs
- ToolBarDesigner.cs
- AlignmentXValidation.cs
- SingleTagSectionHandler.cs