while (progressBar1.Value < LongeurFichier) { LectureBin(); progressBar1.PerformStep(); }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace RecoNAND { public partial class Interface : Form { const int NB_MAX_FICHIER = 25; System.Windows.Forms.OpenFileDialog MonBrowser = new System.Windows.Forms.OpenFileDialog();//Pour aller chercher les fichiers System.IO.BinaryWriter RecoveryNAND = new System.IO.BinaryWriter(File.Create("RecoveryNAND.bin"));//NAND reconstruite List<System.IO.BinaryReader> ListFichierBIN = new List<System.IO.BinaryReader>();//Pour stocker les fichiers long LongeurFichier = -1; public Interface() { InitializeComponent(); } public void RAZ() { listBox1.Items.Clear(); listBox2.Items.Clear(); ListFichierBIN.Clear(); LongeurFichier = -1; } private void buttonAjoutDump_Click(object sender, EventArgs e) { MonBrowser.Multiselect = true; MonBrowser.ShowDialog(); listBox1.Items.Remove("Selectionner les fichiers..."); foreach(string PathFile in MonBrowser.FileNames) { ListFichierBIN.Add(new System.IO.BinaryReader(File.Open(PathFile, FileMode.Open))); listBox1.Items.Add(PathFile); } } private void buttonComparer_Click(object sender, EventArgs e) { // Enable the Cancel button while // the asynchronous operation runs. this.cancelAsyncButton.Enabled = true; backgroundWorker1.RunWorkerAsync("Comparer"); } private void Comparer_Fichier(BackgroundWorker worker, DoWorkEventArgs e) { if (worker.CancellationPending) { e.Cancel = true; } else { //Mettre ici la comparaison des fichiers } } private void aideToolStripMenuItem_Click(object sender, EventArgs e) { Aide monAide = new Aide(); monAide.ShowDialog(); } private void aProposToolStripMenuItem_Click(object sender, EventArgs e) { APropos monAPropos = new APropos(); monAPropos.ShowDialog(); } private void buttonCreeNAND_Click(object sender, EventArgs e) { LongeurFichier = -1; foreach (System.IO.BinaryReader FileBIN in ListFichierBIN) { if (LongeurFichier == -1) { LongeurFichier = FileBIN.BaseStream.Length; } else if (FileBIN.BaseStream.Length != LongeurFichier) { MessageBox.Show("Les fichiers doivent avoir la même taille."); CloseAllFiles(ListFichierBIN); listBox1.Items.Clear(); listBox1.Items.Add("Selectionner les fichiers..."); listBox2.Items.Add("Impossible de générer la NAND car les fichiers sont de tailles différentes."); break; } } // Enable the Cancel button while // the asynchronous operation runs. this.cancelAsyncButton.Enabled = true; backgroundWorker1.RunWorkerAsync("Creation_NAND"); } public void CloseAllFiles(List<System.IO.BinaryReader> ListToClose) { foreach (System.IO.BinaryReader File in ListToClose) { File.Close(); } } public void Creation_fichier_NAND(BackgroundWorker worker, DoWorkEventArgs e) { int percentComplete = 0; long nbeLu = 0; for (nbeLu = 0; nbeLu < LongeurFichier; ++nbeLu) { if (worker.CancellationPending) { e.Cancel = true; } else { //Ajouter ici la lecture et l'ecriture de la nouvelle NAND dans le fichier RecoveryNAND percentComplete = (int)((float)nbeLu / (float)LongeurFichier * 100); worker.ReportProgress(percentComplete); } } } private void cancelAsyncButton_Click(System.Object sender, System.EventArgs e) { // Cancel the asynchronous operation. this.backgroundWorker1.CancelAsync(); // Disable the Cancel button. cancelAsyncButton.Enabled = false; } // This event handler is where the actual, // potentially time-consuming work is done. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // Get the BackgroundWorker that raised this event. BackgroundWorker worker = sender as BackgroundWorker; // Assign the result of the computation // to the Result property of the DoWorkEventArgs // object. This is will be available to the // RunWorkerCompleted eventhandler. if ((string)e.Argument == "Creation_NAND") { Creation_fichier_NAND(worker,e); } else if ((string)e.Argument == "Comparer") { Comparer_Fichier(worker, e); } } // This event handler deals with the results of the // background operation. private void backgroundWorker1_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e) { // First, handle the case where an exception was thrown. if (e.Error != null) { MessageBox.Show(e.Error.Message); } else if (e.Cancelled) { // Next, handle the case where the user canceled // the operation. // Note that due to a race condition in // the DoWork event handler, the Cancelled // flag may not have been set, even though // CancelAsync was called. listBox2.Items.Add("Opération annulée"); } else { // Finally, handle the case where the operation // succeeded. listBox2.Items.Add("Opération terminée avec succès"); } // Enable the UpDown control. this.buttonCreeNAND.Enabled = true; // Enable the Start button. this.buttonComparer.Enabled = true; // Disable the Cancel button. this.cancelAsyncButton.Enabled = false; } // This event handler updates the progress bar. private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { this.progressBar1.Value = e.ProgressPercentage; } } }
for (nbeLu = 0; nbeLu < LongeurFichier; ++nbeLu) { if (worker.CancellationPending) { e.Cancel = true; } else { //Ajouter ici la lecture et l'ecriture de la nouvelle NAND dans le fichier RecoveryNAND percentComplete = (int)((float)nbeLu / (float)LongeurFichier * 100); worker.ReportProgress(percentComplete); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionif (nbeLu % modulo == 0) { percentComplete += 1; worker.ReportProgress(percentComplete); }
long modulo = LongeurFichier / 19;