This project is read-only.

event hang when refreshing label.text

Aug 11, 2009 at 1:12 AM

Markhor->Thank for all your help. I am slowly working through my project.  I am trying to display progress status on a form using the code below.  Every time I ask it to refresh the label2.text the program hangs and reports "not responding".  Remove the refresh to label2.text and the program works great.  I inserted a messagebox.show to report the same data and it also works greats (obviously I can not use the messagebox because it pause the program).

<font size="2">

 private void button1_Click(object sender, EventArgs e)
        {           
            DateTime vsevenzipsharp = DateTime.Now;
            SevenZipCompressor tmp = new SevenZipCompressor();
            SevenZipCompressor.SetLibraryPath(@"C:\cs video\sevenzipsharp\7z.dll");
            tmp.CompressionLevel = CompressionLevel.Ultra;
            tmp.CompressionMethod = CompressionMethod.Default;
            tmp.DirectoryStructure = true;
            tmp.CustomParameters.Add("mt","on");
            tmp.ScanOnlyWritable = true;
            tmp.PreserveDirectoryRoot = true;
            tmp.CompressionMode = CompressionMode.Create;
            tmp.Compressing += new EventHandler((s, w) =>
              {
                  //label1.Text = String.Format("{0}%", w.PercentDone.ToString());  <-This line will hang the program and produce a "not responding" error.

                  //MessageBox.Show(String.Format("{0}%", w.PercentDone.ToString()));  <-This line will only pause the program but works.
              });
           
            try
            {
               tmp.CompressDirectory(@"c:\Vet\", @"c:\backupfiles\testbackup.7z", "AVA*", false);
            }
            catch(Exception c)
            { MessageBox.Show(c.Message); }
           
            label2.Text = DateTime.Now.Subtract(vsevenzipsharp).ToString();
    

</font>

 

Aug 11, 2009 at 9:10 AM

SevenZipTestForms is an example of using SevenZipSharp in a GUI application. Basically, you need to invoke the event in a friendly thread context. That is,

tmp.Compressing += (s,w) =>
{
    label1.Invoke(new WithoutParametersDelegate(() =>
    {
        label1.Text = "...";
        label1.Refresh();
    }));
}

Aug 11, 2009 at 10:18 PM

Thanks again, I am learning.

Aug 12, 2009 at 7:07 AM

Ask anything you need, you are welcome!