Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have a problem of multiple steps
C#
step1:
    step1();
    if(step1 == true)
step2:
    step2();
       else goto step1;
    if(step2 == true)
step3();
    else goto step2;
and so on

i need another solution for this i get something about using WithRetry(()=>action, ()=>retry);
anyone have experience with this thing

thanks for help
Posted
Updated 7-Jul-12 7:24am
v2
Comments
Sergey Alexandrovich Kryukov 7-Jul-12 13:49pm    
What do you mean by that, exactly? What you show won't compile in C#.

Formulate what do you want formally exactly, and implement it literally.
--SA
[no name] 7-Jul-12 14:40pm    
Most problems are "problem of multiple steps"... What is it that you are trying to do? This is not a real question as it stands. You can probably easily accomplish whatever it is that you are trying to do but the "code" that you posted does not do anything.
Philippe Mori 7-Jul-12 15:16pm    
Your sample code would be considered bad code...

If you retry exactly the same steps, why would you specify an alternate action in your question after the sample?
Waleedkassem 15-Jul-12 6:47am    
this is not a piece of code the problem is the application passes through multiple states state1, state2 and so on, to get into state2 and perform the actions related to this state must state1 actions done and get some inputs and a user event from a gui if the user click back on state2 corresponding gui i need to go to state1 note each state contains multiple screens so i have to go the corresponding screen, i did it with goto but i need a daynamic way where i have 12 states on back on any state i have to get back to previous state. there is a time out on user interaction with the gui i have also to handle thanks for any help

1 solution

I think that something similar to this should do (not tested):

C#
public void ExecuteStepAndRetryIfFailed(params Func<bool>[] allSteps)
{
   foreach (var step in allSteps)
   {
      while (!step()) { }
   }
}


But you would have to have a mean to ensure it won't loop indefinitly if a step always fail. For example, you might execute a step up to 3 times and if it still fails, abort any remainding step.
 
Share this answer
 
v3
Comments
Waleedkassem 8-Jul-12 8:39am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900