public bool Upload(GoogleDrive googleDrive) { bool result = false; tokenSource = new CancellationTokenSource(); manualReset = new ManualResetEvent(true); finIndicator = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(async x => { this.IsAlive = true; try { if (this.ID.IsNullOrEmptyOrWhiltSpace() || this.mDatabase is null) { result = await googleDrive.UploadResumableAsync(this.FullPath, this.RemotePath, tokenSource.Token, this.manualReset) != null; } else { string uri = this.mDatabase.GetFileUploadID(this.ID); string getID(bool force) { if (string.IsNullOrWhiteSpace(uri) || force) { uri = googleDrive.GenerateUploadID(this.FullPath, this.RemotePath); this.mDatabase.SetUploadStatus(this.ID, uri); } return(uri); } var id = await googleDrive.UploadResumableAsync(this.FullPath, getID, tokenSource.Token, this.manualReset); if (!id.IsNullOrEmptyOrWhiltSpace()) { this.mDatabase.SetUploadStatus(this.ID, id, true); result = true; } else { result = false; } } } catch (Exception ex) { ex.Message.ErrorLognConsole(); return; } finally { this.IsAlive = false; finIndicator.Set(); } }); try { finIndicator.WaitOne(); } finally { tokenSource.Dispose(); manualReset.Dispose(); GC.Collect(); } return(result); }