本文整理匯總了C#中System.Progress.UpdateInstall方法的典型用法代碼示例。如果您正苦於以下問題:C# Progress.UpdateInstall方法的具體用法?C# Progress.UpdateInstall怎麽用?C# Progress.UpdateInstall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Progress
的用法示例。
在下文中一共展示了Progress.UpdateInstall方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CopyDirectoryAsync
public static Task CopyDirectoryAsync(string source, string destination, Progress progress) => Task.Run(() =>
{
progress.UpdateInstall(0);
var total = Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories).Count();
var current = 0;
CopyDir(source, destination, progress, total, ref current);
});
示例2: CopyDir
// From http://stackoverflow.com/questions/677221/copy-folders-in-c-sharp-using-system-io
//
static void CopyDir(string source, string destination, Progress progress, int total, ref int current)
{
var src = new DirectoryInfo(source);
var dest = new DirectoryInfo(destination);
if (!dest.Exists)
{
dest.Create();
}
// Copy all files
var files = src.GetFiles();
foreach (var file in files)
{
file.CopyTo(Path.Combine(dest.FullName, file.Name), true);
current++;
progress.UpdateInstall((int)Math.Round((double)current / total * 100.0));
}
// Process subdirectories
var dirs = src.GetDirectories();
foreach (var dir in dirs)
{
// Get destination directory
var destinationDir = Path.Combine(dest.FullName, dir.Name);
// Call CopyDirectory() recursively.
CopyDir(dir.FullName, destinationDir, progress, total, ref current);
}
}