none
Updating label during copy/move stalls. RRS feed

  • Question

  • I perform a MoveDir inside a While loop:

    For Each foundDir In My.Computer.FileSystem.GetDirectories(lblSrc.Text)
    ...
    lblMessage.Text = "Moving..." lblTarget.Text = strDestPath & "\" & strTargetFolder Cursor = Cursors.WaitCursor lblMessage.Refresh() lblTarget.Refresh() My.Computer.FileSystem.MoveDirectory(foundDir, strDestPath & "\" & strTargetFolder, True)
    ...
    Next


    "lblTarget"
    shows the folder currently being moved. Sometimes it stops refreshing after only a couple of files and you can't tell anything is happening until the end.

    How do I force the label to update so it shows every file being moved? (No solution that involves "pausing" the copy process for even a split second is an option because of the number of files being moved.)

    TIA





    Wednesday, November 28, 2018 2:53 PM

Answers

  • Hi

    You can use Application.DoEvents on the next line to force the Label update.

    However, many paople are under the impression that those who use DoEvents don't know what it is, otherwise, they wouldn't use it :)


    Regards Les, Livingston, Scotland

    Wednesday, November 28, 2018 3:00 PM

All replies

  • Hi

    You can use Application.DoEvents on the next line to force the Label update.

    However, many paople are under the impression that those who use DoEvents don't know what it is, otherwise, they wouldn't use it :)


    Regards Les, Livingston, Scotland

    Wednesday, November 28, 2018 3:00 PM
  • Hello,

    Have you considered the overload for MoveDirectory?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, November 28, 2018 3:14 PM
    Moderator
  • Hello,

    Have you considered the overload for MoveDirectory?


    Sorry for the late reply.

    I don't know how to implement C# code from VB.

    Wednesday, November 28, 2018 10:59 PM
  • I don't know how to implement C# code from VB.

     There is no C# to VB conversion needed,  she is simply asking if you have considered using the overload of the MoveDirectory which uses a 3rd and 4th parameter.  It will allow you to pop up a small dialog showing the move progress of the directory,  just like the system would show when you move them in an explorer window.

     PS - You should do the moving inside a separate thread and using a delegate sub to report the name/progress back to the form's thread.  That would keep your Form from freezing up and having problems updating your label.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Wednesday, November 28, 2018 11:45 PM
    Wednesday, November 28, 2018 11:21 PM
  • Hello,

    Have you considered the overload for MoveDirectory?


    Sorry for the late reply.

    I don't know how to implement C# code from VB.

    If you look on the page it has an example.

    Imports Microsoft.VisualBasic.FileIO
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            My.Computer.FileSystem.MoveDirectory("C:\Data\SQL_Server", "C:\Server", UIOption.AllDialogs)
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, November 28, 2018 11:47 PM
    Moderator
  • You can use Application.DoEvents on the next line to force the Label update.


    This appears to work. :)

    A few more runs to verify and if so, I'll mark this as the answer.

    Thanks.

    FOLLOW-UP: Yes, a few more tests confirm this works. I simply added "Application.DoEvents()" to the line right before my MoveDirectory command and the label that displays the file being copied now properly refreshes with each pass. A nice simple solution. Thx.
    Thursday, November 29, 2018 1:54 AM