Пример #1
0
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                backgroundThread = Thread.CurrentThread;

                filesToAdd = new List <CFile>();
                bldr       = new StringBuilder();

                int counter = 0;
                foreach (string fileName in fileDialog.FileNames)
                {
                    bgWorker.ReportProgress(counter);

                    FileInfo fInfo = new FileInfo(fileName);
                    if (fInfo.Length > Database.MAX_ALLOWED_PACKET_SIZE)
                    {
                        bldr.Append(fInfo.FullName + "\n");
                        continue;
                    }

                    CFile f = new CFile
                    {
                        FileName  = Path.GetFileNameWithoutExtension(fInfo.FullName),
                        Extension = (FileExtension)Enum.Parse(typeof(FileExtension), fInfo.Extension.ToUpper().Replace(".", "")),
                    };

                    if (f.ReadAllBytes(fInfo.FullName))
                    {
                        currentFileName = fInfo.FullName;
                        filesToAdd.Add(f);
                    }
                    else
                    {
                        bldr.Append(fInfo.FullName + "\n");
                    }

                    counter++;
                }
            }
            catch (ThreadAbortException)
            {
            }
        }