I'm writing a (fairly) simple C# application using .NET 4 to check for updates before running an executable. If a newer version of an exe exists on a network share, simply copy it over to the local folder and start it. It's all working perfectly, except while reading about the limitations of File.Copy() I realized that I wasn't going to be able to show a progress bar while I did this, and everything I saw said to use CopyFileEx, so I'm trying to do that.
I used the sample code found here and it compiles fine (although I'm still a little unsure of exactly how the backgroundworker comes into play), except when I actually go to run the application, the CopyFilEx() method returns false, with the error being "The parameter is incorrect".
My code (relevant sections only, I'll add more if need be)
Calling the function:
XCopy.Copy(strServerAppPath + strExeName, strLocalAppPath + strExeName, true, true, (o, pce) =>
{
worker.ReportProgress(pce.ProgressPercentage, strServerAppPath + strExeName);
});
(the source path evaluates to "C:est.txt" and the destination path to "C:estest.txt")
Where the error occurs in the code linked above:
bool result = CopyFileEx(Source, Destination, new CopyProgressRoutine(CopyProgressHandler), IntPtr.Zero, ref IsCancelled, copyFileFlags);
if (!result)
throw new Win32Exception(Marshal.GetLastWin32Error());
Thanks in advance for the help, I've been struggling with this for a few hours now...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…