public WaitHandle RunAsync()
{
if (isRunning)
throw new InvalidOperationException("Import is already running");
try {
/* must be set (as soon as possible) in a function that is _not_ called asynchronously
* (i.e. dont call it in ImportThread()) */
isRunning = true;
importSucceeded = false;
cancellationRequested = false;
asyncOperation = AsyncOperationManager.CreateOperation(null);
Reset();
/* invoke the import function on a new thread and return a waithandle */
Action<string, VolumeDatabase, string, int> it = ImportThread;
IAsyncResult ar = it.BeginInvoke(sourceDbPath, targetDb, dbDataPath, bufferSize, null, null);
return ar.AsyncWaitHandle;
} catch (Exception) {
isRunning = false;
if (asyncOperation != null)
asyncOperation.OperationCompleted();
throw;
}
}