Skip to content

Examples

josemesona edited this page Mar 2, 2017 · 1 revision

Using DismProgressCallback

DismProgressCallback is a delegate that receives progress updates during certain operations.

static void Main(string[] args)
{
    DismApi.Initialize(DismLogLevel.LogErrors);
    try
    {
        using (DismSession session = DismApi.OpenOnlineSession())
        {
            List<string> sourcePaths = new List<string>();

            DismApi.AddCapability(
                session,
                capabilityName: "Capability",
                limitAccess: false,
                sourcePaths: new List<string>(),
                progressCallback: HandleProgress,
                userData: null);
        }
    }
    finally
    {
        DismApi.Shutdown();
    }
            
}

private static void HandleProgress(DismProgress progress)
{
    // Print the current progress
    //
    Console.WriteLine("Current: {0}", progress.Current);
    Console.WriteLine("Total: {0}", progress.Total);

    if (progress.Current == 50)
    {
        // Cancel the operation at 50%
        //
        progress.Cancel = true;
    }
}
Clone this wiki locally