public Task<IWordPredictorEngine> CreateAsync( string predictorName )
{
//if the last is still running
if( _currentlyRunningTask != null && _currentlyRunningTask.Status <= TaskStatus.Running )
{
Debug.Assert( cancellationSource != null );
cancellationSource.Cancel();
//_currentlyRunningTask.Wait( cancellationSource.Token );
cancellationSource.Dispose();
cancellationSource = new CancellationTokenSource();
}
if( cancellationSource == null )
cancellationSource = new CancellationTokenSource();
string p = _pluginResourceDirectory();
string userPath = _userPath();
_currentlyRunningTask = Task.Factory.StartNew<IWordPredictorEngine>( () =>
{
if( cancellationSource.IsCancellationRequested )
return null;
SybilleWordPredictorEngine engine = DoCreate( predictorName, p, userPath, _predictorFeature );
if( engine.ConstructionSuccess ) return engine;
return null;
}, cancellationSource.Token );
return _currentlyRunningTask;
}