---
# System prepended metadata

title: 'Issue: precise command timeout'

---

# Issue: precise command timeout

```c#
public int Execute_extended(ICommand command)
{
  eRETURN_VALUES returnValue;
  
  if (IsInitialized)
  {
    eRETURN_VALUE threadReturnValue = eRETURN_VALUES.ETIMEOUT;
    
    using(AutoResetEvent autoResetEvent = new AutoResetEvent(false))
    {
      Thread thread = new Thread(() =>
      {
        try
        {
          threadReturnValue = (eRETURN_VALUES)command.Execute();
          autoResetEvent.Set();
        }
        catch (ThreadAbortException)
        {
            threadReturnValue = eRETURN_VALUES.ETIMEOUT;
        }
        finally
        {
          /* do cleanup */
        }
        
        /* Rethrow of Exception */
      });
      
      thread.Start();
      
      if(autoResetEvent.WaitOne(1000))
      {
        /* procedure successful */
        returnValue = threadReturnValue;
      }
      else
      {
        thread.Abort();
        returnValue = eRETURN_VALUES.ETIMEOUT;
      }
      
      thread.Join();
    }
  }
  else
  {
    Instance.Logger.LogError($"{(command as IInstrumentCommand).Device}: Device is not initialized");
    returnValue = eRETURN_VALUES.NOTINITIALIZED;
  }
  
  return (int)returnValue;
}
````