public IEnumerable <ITikReSentence> ExecuteListWithDuration(int durationSec) { Exception asyncException = null; List <ITikReSentence> result = new List <ITikReSentence>(); //Async execute, responses are stored in result list ExecuteAsync( reSentence => { if (_isRuning) { result.Add(reSentence); } }, error => { asyncException = new TikCommandException(this, error); }); //wait for results (in calling =UI? thread) for (int i = 0; i < durationSec * 10; i++) //step per 100ms { Thread.Sleep(100); if (asyncException != null) //ended with exception { throw asyncException; } if (!_isRuning) //already ended (somehow) { break; } } Cancel(); //wait for real cancel while (_isRuning)//TODO loadingThread.Join(); { Thread.Sleep(10); } return(result); }
public IEnumerable<ITikReSentence> ExecuteListWithDuration(int durationSec) { Exception asyncException = null; List<ITikReSentence> result = new List<ITikReSentence>(); //Async execute, responses are stored in result list ExecuteAsync( reSentence => { if (_isRuning) result.Add(reSentence); }, error => { asyncException = new TikCommandException(this, error); }); //wait for results (in calling =UI? thread) for (int i = 0; i < durationSec * 10; i++) //step per 100ms { Thread.Sleep(100); if (asyncException != null) //ended with exception throw asyncException; if (!_isRuning) //already ended (somehow) break; } Cancel(); //wait for real cancel while (_isRuning)//TODO loadingThread.Join(); { Thread.Sleep(10); } return result; }