void bw_DoWork(object sender, DoWorkEventArgs e) { int fileId = 0; try { ////////////////////////////////////////////////////////////////////////// dynamic o = e.Argument; int documentId = (int)o.documentId; int contractorId = (int)o.contractorId; string version = (string)o.version; if (contractorId <= 0) { ErrorHandler.ShowErrorMessage("ابتدا اطلاعات پيمانکار را ثبت کنيد"); return; // error has occured contractor should be submited before commiting chnages } ////////////////////////////////////////////////////////////////////////// string fileLocation = OpenFileHandler.OpenFileToUpload(); byte[] fileContent = OpenFileHandler.GetFileFromLocation(fileLocation); string fileName = System.IO.Path.GetFileName(fileLocation); fileId = DataManagement.AddContractorFile(fileName, version, contractorId, documentId, fileContent); fileContent = null; GC.Collect(); } catch (System.Exception ex) { ErrorHandler.ShowErrorMessage("ثبت فایل با موفقیت انجام نشد لطفا دوباره سعی کنید!"); } }