Showing "Work in progress" window while copying files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laszo Pasztor
    New Member
    • Feb 2011
    • 6

    Showing "Work in progress" window while copying files

    Hi!

    I'm writing an application in which I'm copying a few files. It takes a while, that's why I would like to open a window which would say "Work in progress", so the user would know that copying is in progress and he should wait until it finishes. After finishing the copy-progress, the little notification window should close and let the user continue the work with the application.
    I tried to solve this, but when I made the message-window open the copy wouldn't start (it was after the message window-opening in the code), only when I closed that window.
    So maybe I should use threads, one would handle the copying while the other would handle the message window and close it when the copying is ready.
    But I don't know how to solve this.

    Could anybody help, please?

    Thanks!
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    A BackgroundWorke r should help you out here. Have a look at the MSDN page, it explains it in detail and provides a few examples.

    Comment

    • Laszo Pasztor
      New Member
      • Feb 2011
      • 6

      #3
      Thanks, but it's not so clear for me.

      Here is the part of my code:

      Code:
      DirectoryInfo diForrasStilusok = new DirectoryInfo(strForrasKonyvtar + "\\Stilusok" + strStilus);
      DirectoryInfo diCelStilusok = new DirectoryInfo(strMunkaKonyvtar);
      CopyAll(diForrasStilusok, diCelStilusok);
      It's called by a button-pressing. Before (or when) this part of the code would start, I would like to make a new window (Form, let' say Form1) open, and close it as soon as the copying process finishes.

      Could you please expand my code? This BackgroundWorke r seems to be not so clear to me.

      Thanks!

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Read the MSDN article.

        What you have in CopyAll is probably going to be what goes in the DoWork method for your BGW. The ProgressChanged event is where you'll update your GUI (Form1, per your post) to reflect the status of the copy.

        Dive in and start writing code, if you get bogged down post what you've got and we'll go through it :)

        Comment

        • Laszo Pasztor
          New Member
          • Feb 2011
          • 6

          #5
          Hi!
          I tried, really, but can't understand...

          Please help me make this little example. With this I'm sure I would understand the working of BackgroundWorke r.

          So:

          Let's have two forms, Form1 and Form2. Form1 contains one button, called Start. When this Start button is pressed, the Form1 would start a process, for example sleep for 5 seconds (Thread.Sleep(5 000);), and the Form2 window opens. After the 5 seconds end, the Form2 window closes.

          Thats all.

          Could you please help me create this little example?

          Thank you!

          Comment

          • Laszo Pasztor
            New Member
            • Feb 2011
            • 6

            #6
            Ok, I could figure out a working solution:

            Code:
            public void AdatokFeldolgozasaForm()
                    {
                        AdatokFeldolgozasa frmAdatokFeldolgozasa = new AdatokFeldolgozasa();
                        frmAdatokFeldolgozasa.ShowDialog();
                    }
            To call it:
            Code:
            Thread tAdatokFeldolgozasa = new Thread(new ThreadStart(AdatokFeldolgozasaForm));
                        tAdatokFeldolgozasa.Start();
            To end it:
            Code:
            tAdatokFeldolgozasa.Abort();
            So. It's working fine, BUT:

            - It doesn't "lock" the main application as ShowDialog should do. I still can use the main form, but I want to prevent it from using while this new window is shown.
            - I can't make it appear in the center of the main form. It's set to CenterParent, but it appears in the top left corner.

            Any ideas to solve these problems?

            Thanks!

            Comment

            • Laszo Pasztor
              New Member
              • Feb 2011
              • 6

              #7
              Ok, I could solve it:

              Code:
              public void AdatokFeldolgozasaForm()
                      {
                          AdatokFeldolgozasa frmAdatokFeldolgozasa = new AdatokFeldolgozasa();
              
                          int X = this.Left + (this.Width - frmAdatokFeldolgozasa.Width) / 2;
                          int Y = this.Top + (this.Height - frmAdatokFeldolgozasa.Height) / 2;
                          frmAdatokFeldolgozasa.Location = new Point(X, Y);
              
                          frmAdatokFeldolgozasa.ShowDialog();
                      }
              
              
              Thread tAdatokFeldolgozasa = new Thread(new ThreadStart(AdatokFeldolgozasaForm));
                              tAdatokFeldolgozasa.Start();
              
              tAdatokFeldolgozasa.Abort();

              Comment

              Working...