• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Windows Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Windows Developer Center > Software Development for Windows Client Forums > Windows Workflow Foundation > While loop with delay inside in custom activity in state machine workflow.
Ask a questionAsk a question
Search Forums:
  • Search Windows Workflow Foundation Forum Search Windows Workflow Foundation Forum
  • Search All Software Development for Windows Client Forums Search All Software Development for Windows Client Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerWhile loop with delay inside in custom activity in state machine workflow.

  • Wednesday, June 06, 2007 8:10 AMyalp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Hello,
    I am doing state machine workflow and I want create some custom activity which I could use in different places. But I need some loop in this activity which do sth ten times every 30 minutes.
    I heve tried to derive from SequntialActivity and put to this While activity and in this loop CodeActivity and Delay activity. But of course I can't put such made activity to the state activity (to StateInitialiyation because it can't contain delay activity; to EventDriven because first activity must derive from IEventActivity - and only first). I want delay activity instead of  for example sleep() in code activity because I want workflow to unload to db when it's waiting.
    So what I should do in such situation? Maybe I should implement IEventActivity? But I am afraid of this because I really have no idea how I should write this to resolve problem.
    Maye there is other way to put this activity to state?
    Or maybe I should unload workflow and the load it by myself? But how do this properly?
    I would be glad for any suggestions.
    Thanks,
    Krzysztof

    • ReplyReply
    • QuoteQuote
     

Answers

  • Sunday, June 10, 2007 12:53 AMDave Green - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    I think you're caught between conflicting design requirements.  On the one hand, you're trying to build a long running custom activity which loops performing a periodic action, and on the other hand, you're trying to build a single custom activity that is useful everywhere.  But an event handler in a state machine is not intended to be long running - the whole idea is that each event and its processing should be a short, sharp single unit.  In fact, a state machine should only ever process one event at a time.

     

    So what to do?  I think that the right answer here is to factor your solution out.  What if you have one custom activity (A) that performs the action to be repeated just once.  Then in a state machine, use Delay followed by A to achieve the looping effect.  Then build a second custom activity (B) that contains a While which in turn contains Delay followed by A.  Now, B is a long running activity that can be used in a sequential flow, say.

     

    You may have better ideas on how to factor this out.  However, I think the point is that the problem, as you state it, needs to be factored out to resolve the conflicting design requirements you describe.

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Monday, June 11, 2007 1:27 PMVidok Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello,

     

    In fact we want to have an activity similar to Delay activity. In our case we want to persist workflow for some time (e.g. 30sec). After that period our activity should check if can “unlock” the workflow. “Unlock” information will be in database (some kind of flag/semaphore). If semaphore is still closed then workflow should be persisted for next 30 sec.

     

    Is it possible to inherit from Delay activity and implement such functionality?

    • ReplyReply
    • QuoteQuote
     
  • Tuesday, September 04, 2007 6:31 PMRobert te Kaat - IS Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    You could create a custom delay activity which itself decides whether to remain 'executing' or to switch to 'closed'.

    My article (incl. source-code) may help you with that: http://blogs.infosupport.com/porint/archive/2007/09/04/Configurable-Delay-activity-for-WF.aspx

    • ReplyReply
    • QuoteQuote
     
  • Thursday, March 06, 2008 7:59 PMJHubSharp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Dave, is there a recommendation by MS on how to use DelayActivities within a StateMachine? In your example, you've provided a solution for refactoring out the solution, but in the end, the activity still cannot be used within a state machine because I can't support both HandleExternalEvent and delay.

     

    What I want is the ability to make an external method call and, if the call fails, to try again in an hour or so. If there's a more appropriate way to solve this than a delay activity, could you explain?

     

    Thanks!

     

    Shawn

    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement