Question

I am planning to develop a File organize software which detect files arrive to special folder and copy those files to specific folder (Ex .txt files goes to Text Doc folder). I'm using FileSystemWatcher.

for detect files. So I want to know whether the file or folder copying operation (Manually copy file or folder) is finish or not by C# code.

With single file program is ok. but for multiple files need to improve the program.

I used this loop to check whether file is release or not, but with large files this makes the program not responded.

void File_move(string source,string destination)
        {
            EE:
                try
                {
                    File.Move(source, destination);
                }
                catch (Exception ex)
                {
                    lblStatus.Text = "Waiting for file copping complete";
                    Application.DoEvents();
                    goto EE;
                }

        }
Was it helpful?

Solution

After long time I found a solution for my own question. Here is the link for get file copy progress in both c# and vb.net

http://pinvoke.net/default.aspx/kernel32/CopyFileEx.html

In this sample code we can get progress of copping a file

private CopyProgressResult CopyProgressHandler(long total, long transferred, long streamSize, long StreamByteTrans, uint dwStreamNumber,CopyProgressCallbackReason reason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData)
    {
        Progressbar.Max=Convert.ToInt32(total);
        Progressbar.Value=Convert.ToInt32(transferred);
        Application.Doevents();
        return CopyProgressResult.PROGRESS_CONTINUE;
    }

long total gives total size and long transferred gives current progress

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top