-
Notifications
You must be signed in to change notification settings - Fork 223
Open
Description
I pulled the latest master branch of VssApi code, and run a sample test. I found that it took very long time to list the system writer component files.
I guess for IReadOnlyList it was lazy load, every time we got item it invoke COM method?
Thanks!
Here is the sample code:
using System.Diagnostics;
using System.Runtime.InteropServices;
using Vanara.PInvoke;
using Vanara.PInvoke.VssApi;
namespace ConsoleApp1
{
internal class Program
{
[System.Runtime.InteropServices.DllImport("ole32.dll")]
public static extern int CoInitializeSecurity(IntPtr pVoid, int
cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, int level,
int impers, IntPtr pAuthList, int dwCapabilities, IntPtr
pReserved3);
static void Main(string[] args)
{
try
{
// Invoke CoInitializeSecurity to get system writer listed.
Marshal.ThrowExceptionForHR(CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero,
1, 3, IntPtr.Zero, 0x00, IntPtr.Zero));
Console.WriteLine("Initializing VSS Backup Components...");
IVssBackupComponents ppBack;
HRESULT hr = VssFactory.CreateVssBackupComponents(out ppBack);
hr.ThrowIfFailed();
Console.WriteLine("Successfully created IVssBackupComponents instance.");
ppBack.InitializeForBackup(null);
ppBack.SetBackupState(true, true, VSS_BACKUP_TYPE.VSS_BT_FULL, false);
ppBack.SetContext(VSS_SNAPSHOT_CONTEXT.VSS_CTX_BACKUP);
IVssAsync getAsync = ppBack.GatherWriterMetadata();
getAsync.Wait();
getAsync.QueryStatus(out hr);
hr.ThrowIfFailed();
foreach (IVssExamineWriterMetadata writeMeta in ppBack.WriterMetadata)
{
writeMeta.GetIdentity(out var pidInstance,
out var pidWriter,
out var WriteName,
out var pInstanceName,
out var usage,
out var source);
Console.WriteLine("Get compoment for writer:{0}", WriteName);
foreach (IVssWMComponent component in writeMeta.Components)
{
Console.WriteLine(DateTime.Now.ToString() + "start add expand path for writer:{0}", WriteName);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int k = 0; k < component.Files.Count; k++)
{
// DO nothing here;
// For system writer it took very very long time.
}
stopwatch.Stop();
TimeSpan elapsedTime = stopwatch.Elapsed;
Console.WriteLine(DateTime.Now.ToString() + "add expand path for writer:{0}, file count:{1}, took:{2} seconds",
WriteName, component.Files.Count, elapsedTime.TotalSeconds);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error initializing VSS: {0}" + ex);
}
}
}
}
For normal case, it should take about 26 seconds. But here it took 400+ seconds.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels