Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / Delay.cs / 1305376 / Delay.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Statements { using System; using System.Activities; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime; using System.Windows.Markup; [ContentProperty("Duration")] public sealed class Delay : NativeActivity { static FuncgetDefaultTimerExtension = new Func (GetDefaultTimerExtension); Variable timerBookmark; public Delay() : base() { this.timerBookmark = new Variable (); } [RequiredArgument] [DefaultValue(null)] public InArgument Duration { get; set; } protected override bool CanInduceIdle { get { return true; } } protected override void CacheMetadata(NativeActivityMetadata metadata) { RuntimeArgument durationArgument = new RuntimeArgument("Duration", typeof(TimeSpan), ArgumentDirection.In, true); metadata.Bind(this.Duration, durationArgument); metadata.SetArgumentsCollection(new Collection { durationArgument }); metadata.AddImplementationVariable(this.timerBookmark); metadata.AddDefaultExtensionProvider(getDefaultTimerExtension); } static TimerExtension GetDefaultTimerExtension() { return new DurableTimerExtension(); } protected override void Execute(NativeActivityContext context) { TimeSpan duration = this.Duration.Get(context); if (duration < TimeSpan.Zero) { throw FxTrace.Exception.ArgumentOutOfRange("Duration", duration, SR.DurationIsNegative(this.DisplayName)); } if (duration == TimeSpan.Zero) { return; } TimerExtension timerExtension = GetTimerExtension(context); Bookmark bookmark = context.CreateBookmark(); timerExtension.RegisterTimer(duration, bookmark); this.timerBookmark.Set(context, bookmark); } protected override void Cancel(NativeActivityContext context) { Bookmark timerBookmark = this.timerBookmark.Get(context); TimerExtension timerExtension = GetTimerExtension(context); timerExtension.CancelTimer(timerBookmark); context.RemoveBookmark(timerBookmark); context.MarkCanceled(); } protected override void Abort(NativeActivityAbortContext context) { Bookmark timerBookmark = this.timerBookmark.Get(context); // The bookmark could be null in abort when user passed in a negative delay as a duration if (timerBookmark != null) { TimerExtension timerExtension = GetTimerExtension(context); timerExtension.CancelTimer(timerBookmark); } base.Abort(context); } TimerExtension GetTimerExtension(ActivityContext context) { TimerExtension timerExtension = context.GetExtension (); Fx.Assert(timerExtension != null, "TimerExtension must exist."); return timerExtension; } } } // 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
- Triplet.cs
- DbFunctionCommandTree.cs
- PageThemeParser.cs
- Triplet.cs
- MaterialCollection.cs
- ChannelManager.cs
- Expressions.cs
- UnauthorizedWebPart.cs
- AttachmentCollection.cs
- AttributeXamlType.cs
- CommandPlan.cs
- XamlClipboardData.cs
- ChannelManager.cs
- MaskedTextProvider.cs
- ContentOperations.cs
- OdbcParameter.cs
- InvalidDocumentContentsException.cs
- RectangleGeometry.cs
- GlyphInfoList.cs
- RecordsAffectedEventArgs.cs
- DES.cs
- VSWCFServiceContractGenerator.cs
- ConnectionOrientedTransportElement.cs
- PropertyGridView.cs
- UpDownBase.cs
- IdentityReference.cs
- InputProcessorProfiles.cs
- ActivityMetadata.cs
- DSACryptoServiceProvider.cs
- FieldNameLookup.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- DefaultPrintController.cs
- HttpDictionary.cs
- TextModifier.cs
- OleDbDataAdapter.cs
- BrowserInteropHelper.cs
- Unit.cs
- PropertyConverter.cs
- SqlClientPermission.cs
- IfAction.cs
- HttpWebRequestElement.cs
- RelationalExpressions.cs
- ModelFactory.cs
- ExecutedRoutedEventArgs.cs
- DesignerActionService.cs
- XsltArgumentList.cs
- HttpResponseHeader.cs
- Trace.cs
- Vector3DValueSerializer.cs
- PrintingPermission.cs
- WindowsPen.cs
- ErrorStyle.cs
- ServiceModelEnumValidator.cs
- StrongNamePublicKeyBlob.cs
- AspNetHostingPermission.cs
- XsdValidatingReader.cs
- CodeSnippetExpression.cs
- BigInt.cs
- IdleTimeoutMonitor.cs
- DataGridViewCellCollection.cs
- SamlAuthorityBinding.cs
- latinshape.cs
- GeneralTransformCollection.cs
- EncryptedKey.cs
- EmptyEnumerable.cs
- CompilerGlobalScopeAttribute.cs
- DropAnimation.xaml.cs
- ColumnMapTranslator.cs
- RSAOAEPKeyExchangeDeformatter.cs
- RelationshipEnd.cs
- ValidatorCollection.cs
- DocumentPageHost.cs
- RectangleConverter.cs
- HandleRef.cs
- COM2PropertyPageUITypeConverter.cs
- IdentityModelDictionary.cs
- BitSet.cs
- BamlTreeUpdater.cs
- PreProcessInputEventArgs.cs
- TransferRequestHandler.cs
- EventMappingSettingsCollection.cs
- RadioButtonList.cs
- ToolBarButton.cs
- GridViewDeleteEventArgs.cs
- TextTreeUndoUnit.cs
- TreeNodeCollection.cs
- XamlVector3DCollectionSerializer.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- XmlSchemaAppInfo.cs
- Operator.cs
- Decoder.cs
- RepeatBehavior.cs
- OracleColumn.cs
- CalendarTable.cs
- AttributeQuery.cs
- SignatureHelper.cs
- EntityProviderFactory.cs
- RepeaterCommandEventArgs.cs
- TreeNodeConverter.cs
- ArgumentValidation.cs