Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / Parallel.cs / 1305376 / Parallel.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Statements { using System.Activities; using System.Activities.Validation; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows.Markup; using System.Runtime.Collections; [ContentProperty("Branches")] public sealed class Parallel : NativeActivity { CompletionCallbackonConditionComplete; Collection branches; Collection variables; Variable hasCompleted; public Parallel() : base() { } 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 CompletionCondition { get; set; } [DependsOn("CompletionCondition")] public Collection Branches { get { if (this.branches == null) { this.branches = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } } }; } return this.branches; } } protected override void CacheMetadata(NativeActivityMetadata metadata) { Collection children = new Collection (); foreach (Activity branch in this.Branches) { children.Add(branch); } if (this.CompletionCondition != null) { children.Add(this.CompletionCondition); } metadata.SetChildrenCollection(children); metadata.SetVariablesCollection(this.Variables); if (this.CompletionCondition != null) { if (this.hasCompleted == null) { this.hasCompleted = new Variable (); } metadata.AddImplementationVariable(this.hasCompleted); } } protected override void Execute(NativeActivityContext context) { if (this.branches != null && this.Branches.Count != 0) { CompletionCallback onBranchComplete = new CompletionCallback(OnBranchComplete); for (int i = this.Branches.Count - 1; i >= 0; i--) { context.ScheduleActivity(this.Branches[i], onBranchComplete); } } } protected override void Cancel(NativeActivityContext context) { // If we don't have a completion condition then we can just // use default logic. if (this.CompletionCondition == null) { base.Cancel(context); } else { context.CancelChildren(); } } void OnBranchComplete(NativeActivityContext context, ActivityInstance completedInstance) { if (this.CompletionCondition != null && !this.hasCompleted.Get(context)) { // If we haven't completed, we've been requested to cancel, and we've had a child // end in a non-Closed state then we should cancel ourselves. if (completedInstance.State != ActivityInstanceState.Closed && context.IsCancellationRequested) { context.MarkCanceled(); this.hasCompleted.Set(context, true); return; } if (this.onConditionComplete == null) { this.onConditionComplete = new CompletionCallback (OnConditionComplete); } context.ScheduleActivity(this.CompletionCondition, this.onConditionComplete); } } void OnConditionComplete(NativeActivityContext context, ActivityInstance completedInstance, bool result) { if (result) { context.CancelChildren(); this.hasCompleted.Set(context, true); } } } } // 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
- SolidColorBrush.cs
- StartUpEventArgs.cs
- SchemaElementDecl.cs
- _ScatterGatherBuffers.cs
- PropertyEmitter.cs
- RowVisual.cs
- ProcessHostMapPath.cs
- SelectionBorderGlyph.cs
- Clipboard.cs
- TiffBitmapEncoder.cs
- HighlightVisual.cs
- Message.cs
- FixedSOMPageElement.cs
- RoleManagerEventArgs.cs
- SQLInt16.cs
- GlobalizationAssembly.cs
- DependentTransaction.cs
- HealthMonitoringSectionHelper.cs
- ObjectViewQueryResultData.cs
- PersonalizationDictionary.cs
- Scheduler.cs
- WebEventCodes.cs
- DesignerVerbCollection.cs
- FormView.cs
- TextEditorParagraphs.cs
- Site.cs
- TreeNode.cs
- SystemIPGlobalStatistics.cs
- NonSerializedAttribute.cs
- GraphicsPathIterator.cs
- ThreadStateException.cs
- DbModificationClause.cs
- ImageField.cs
- SmtpReplyReader.cs
- DynamicRenderer.cs
- ManipulationDeltaEventArgs.cs
- PropagatorResult.cs
- WorkflowDesignerMessageFilter.cs
- DocumentXmlWriter.cs
- MediaPlayerState.cs
- SqlOuterApplyReducer.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- DataError.cs
- AudioException.cs
- infer.cs
- ProfileManager.cs
- FunctionDescription.cs
- SchemaImporterExtensionsSection.cs
- XmlSchemaSet.cs
- Point3DCollection.cs
- TextRangeProviderWrapper.cs
- SqlDataSourceEnumerator.cs
- RectangleHotSpot.cs
- GeneratedView.cs
- PageHandlerFactory.cs
- DataMisalignedException.cs
- SubstitutionList.cs
- QuaternionAnimation.cs
- StorageBasedPackageProperties.cs
- PopupControlService.cs
- HttpCapabilitiesBase.cs
- SocketException.cs
- Hash.cs
- MatrixTransform3D.cs
- CounterSampleCalculator.cs
- ListSourceHelper.cs
- ResXResourceReader.cs
- XmlWrappingWriter.cs
- StyleHelper.cs
- SourceLineInfo.cs
- storepermissionattribute.cs
- CodeConstructor.cs
- SerialReceived.cs
- Assert.cs
- UnsafePeerToPeerMethods.cs
- DataGridViewAutoSizeModeEventArgs.cs
- WindowsAuthenticationModule.cs
- BindingCollectionElement.cs
- HtmlElement.cs
- VarInfo.cs
- EntryPointNotFoundException.cs
- _IPv4Address.cs
- FilterException.cs
- SecurityImpersonationBehavior.cs
- NoneExcludedImageIndexConverter.cs
- DPTypeDescriptorContext.cs
- Itemizer.cs
- HwndStylusInputProvider.cs
- ComponentEditorForm.cs
- OdbcTransaction.cs
- InProcStateClientManager.cs
- BufferModesCollection.cs
- DBParameter.cs
- SerializationStore.cs
- MethodResolver.cs
- DesignTimeVisibleAttribute.cs
- MemberExpression.cs
- TcpAppDomainProtocolHandler.cs
- NativeStructs.cs
- MetadataExchangeClient.cs