Class RetryPolicy
Configures and executes retry behaviour for SAP GUI operations.
Obtain an instance via WithRetry(int, int):
session.WithRetry(maxAttempts: 3, delayMs: 500).Run(() =>
{
session.WaitReady();
session.TextField("wnd[0]/usr/txtFoo").Text = "value";
});
Retries on SapComponentNotFoundException (slow screen loads) and TimeoutException (session still busy). Never retries on SapGuiNotFoundException — that is a fatal setup error.
public sealed class RetryPolicy
- Inheritance
-
RetryPolicy
- Inherited Members
Constructors
RetryPolicy(int, int)
Creates a retry policy with the given parameters.
public RetryPolicy(int maxAttempts = 3, int delayMs = 500)
Parameters
maxAttemptsintMaximum number of attempts. Must be ≥ 1.
delayMsintMilliseconds to wait between attempts. Must be ≥ 0.
Properties
DelayMs
Delay between attempts in milliseconds (≥ 0). Default: 500.
public int DelayMs { get; }
Property Value
MaxAttempts
Maximum number of execution attempts (≥ 1). Default: 3.
public int MaxAttempts { get; }
Property Value
Methods
Run(Action)
Executes action up to MaxAttempts times,
sleeping DelayMs ms between attempts.
public void Run(Action action)
Parameters
actionActionThe operation to execute and potentially retry.
Exceptions
- SapGuiNotFoundException
Always rethrown immediately — fatal setup error.
- SapComponentNotFoundException
Thrown after all attempts are exhausted.
- TimeoutException
Thrown after all attempts are exhausted.
Run<T>(Func<T>)
Executes func up to MaxAttempts times and
returns its result.
public T Run<T>(Func<T> func)
Parameters
funcFunc<T>The operation to execute and potentially retry.
Returns
- T
The value returned by the first successful execution.
Type Parameters
TReturn type of the operation.
Exceptions
- SapGuiNotFoundException
Always rethrown immediately — fatal setup error.
- SapComponentNotFoundException
Thrown after all attempts are exhausted.
- TimeoutException
Thrown after all attempts are exhausted.