There was a question of the following plan: I want to put ProgressBar about informing the user that files are being checked ( .xlsx ). It checks for sufficient time ... And here, it means that one problem occurs, when checking the program stops responding and, accordingly, the ProgressBar does not fill up, only after the program hangs, the ProgressBar immediately fills up.
private void button4_Click_1(object sender, EventArgs e) { string StartupPath = Application.StartupPath; X509Chain chain = new X509Chain(); string[] file = Directory.GetFiles(Properties.Settings.Default.ExtractDir, textBox1.Text, SearchOption.AllDirectories); // ΠΌΠ΅ΡΠΎΠ΄ ΠΏΠΎΠΈΡΠΊΠ° ΡΠ°ΠΉΠ»ΠΎΠ² ".xlsx" ΠΏΠΎ ΠΌΠ°ΡΡΠΈΠ²Ρ foreach (string ex in file) { string document = Path.Combine(Properties.Settings.Default.ExtractDir, ex); try { using (Package package = Package.Open(document)) // ΠΡΠΊΡΡΠ²Π°Π΅ΠΌ Π΄ΠΎΠΊΡΠΌΠ΅Π½Ρ { listBox1.Items.Add("Π€Π°ΠΉΠ» '" + Path.GetFileName(ex) + "':"); //Π·Π°ΠΏΠΈΡΡ ΡΠ°ΠΉΠ»Π° PackageDigitalSignatureManager dsm = new PackageDigitalSignatureManager(package); if (!dsm.IsSigned) //ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΡ Π½Π° Π½Π°Π»ΠΈΡΠΈΠ΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠΈ { listBox1.Items.Add("ΠΠΎΠΊΡΠΌΠ΅Π½Ρ Π½Π΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π½."); } int count = 1; foreach (PackageDigitalSignature pds in dsm.Signatures) { string s = pds.Signer.GetName(); string text = s.Remove(0, s.IndexOf("CN=")); listBox1.Items.Add(count++ + "." + " ΠΠΎΠ΄ΠΏΠΈΡΡ Π½Π° ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ΅ :" + text); //ΠΏΠΎΠ΄ΠΏΠΈΡΡ Π½Π° ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ΅ if (chain.Build(new X509Certificate2(pds.Signer))) //ΡΡΠ»ΠΎΠ²ΠΈΠ΅ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°ΡΠ° listBox1.Items.Add(" ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°Ρ Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»Π΅Π½"); else listBox1.Items.Add(" ΡΠ΅ΡΡΠΈΡΠΈΠΊΠ°Ρ Π½Π΅Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»Π΅Π½"); } } } catch // ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ { listBox1.Items.Add("Π€Π°ΠΉΠ» '" + Path.GetFileName(ex) + "':"); listBox1.Items.Add("- Π½Π΅Π²Π΅ΡΠ½ΡΠΉ ΡΠΎΡΠΌΠ°Ρ "); } } }
ProgressBar. But not the point, as examples I will give a couple of links: Async Progress Bar Update and Async / Await with a WinForms ProgressBar . - Denis Bubnov