Skip to content

Property AutoRestart

Namespace: Belay.Attributes
Assembly: Belay.Attributes.dll

AutoRestart

Gets or sets a value indicating whether gets or sets whether the thread should automatically restart if it terminates unexpectedly. When true, the thread will be monitored and restarted if it exits due to an error.

csharp
public bool AutoRestart { get; set; }

Property Value

bool

Examples

[Thread(AutoRestart = true)]
public async Task StartDataLoggerAsync()
{
    await ExecuteAsync(@"
        import _thread

        def data_logger():
            while True:
                try:
                    # Log data with error recovery
                    log_sensor_data()
                    time.sleep(60)
                except Exception as e:
                    print(f'Logger error: {e}')
                    time.sleep(10)  # Brief recovery delay

        _thread.start_new_thread(data_logger, ())
    ");
}

Remarks

Auto-restart is useful for critical background operations that should continue running despite occasional errors. However, use with caution as rapidly failing threads can consume device resources.

Auto-restart includes backoff logic to prevent rapid restart loops:

  • Initial restart delay of 1 second
  • Exponential backoff up to maximum of 60 seconds
  • Reset backoff after successful run of 5 minutes

Released under the Apache License 2.0.