private void Finish(int Success, int ErrCode, Exception Error = null) { // Release the HttpWebResponse resource. if (response != null) { response.Close(); if (streamResponse != null) { streamResponse.Close(); } if (streamWriter != null) { streamWriter.Close(); } } response = null; request = null; streamResponse = null; BufferRead = null; if (Success == 1) { try { if (File.Exists(mDlPath + @"\" + mDlName)) { File.Delete(mDlPath + @"\" + mDlName); } File.Move(mDlPath + @"\" + mDlName + ".tmp", mDlPath + @"\" + mDlName); } catch { AppLog.Debug("Failed to rename download {0}", mDlPath + @"\" + mDlName + ".tmp"); mDlName += ".tmp"; } try { File.SetLastWriteTime(mDlPath + @"\" + mDlName, lastTime); } catch { } // set last mod time } else if (Success == 2) { AppLog.Debug("File already downloaded {0}", mDlPath + @"\" + mDlName); } else { try { File.Delete(mDlPath + @"\" + mDlName + ".tmp"); } catch { } // delete partial file AppLog.Debug("Failed to download file {0}", mDlPath + @"\" + mDlName); } Finished?.Invoke(this, new FinishedEventArgs(Success > 0 ? 0 : Canceled ? -1 : ErrCode, Error)); }