Skip to content
Darren Rose edited this page Feb 8, 2022 · 6 revisions

Implemented Interfaces:

Properties:

Property Name Property Type Description
Name string Custom Name for the object to refer to it by - Has no effect on functionality.

Events:

Methods:

RoboQueue Example Code

The following code was used to set up a RoboQueue job in a window that displays progress and results: (WinForms application). This code runs RoboQueue as ListOnly, then immediately starts the copy operation.

Members of the form

    private bool started;
    private bool cancelled;
    private bool StartOnShown = false;
    private long FilesProcessed = 0;
    private long TotalFiles = 0;    
    
    public RoboSharp.RoboQueue RoboCopyCommands { get; set; }
    public bool IsPaused => RoboCopyCommands.IsPaused;
    public bool IsRunning => RoboCopyCommands.IsRunning;

Code that starts the Copy Operation

    //Run all RoboCopy Command at same time to get the total file counts for each one
    started = true;
    cancelled = false;
    IsComplete = false;

    //Setup Event Handlers
    RoboCopyCommands.OnCommandError += RoboSharpObject_OnCommandError;  //Log to program log
    RoboCopyCommands.OnError += RoboSharpObject_OnError; //Handler that Displays Message to user & issues RoboQueue.StopAll()
    RoboCopyCommands.OnCommandStarted += RoboCopyCommands_OnCommandStarted;
    RoboCopyCommands.TaskFaulted += RoboCopyCommands_TaskFaulted; // Breakpoint in handler is used for debugging the form and logging the exceptions

    // Update labels on the form
    this.Invoke(new Action(() =>
    {
        this.txt_Source.Text = "Scanning Files";
        this.txt_Destination.Text = "Please Wait";
    }));
                
    // Await Count - Runs all List-Only jobs at same time
    RoboCopyCommands.ForEach(cmd => cmd.CopyOptions.MultiThreadedCopiesCount = 3);
    RoboCopyCommands.MaxConcurrentJobs = 0;
    IRoboQueueResults ListResults = await RoboCopyCommands.StartAll_ListOnly();
    TotalFiles = ListResults.FilesStatistic.Total; //Assign value for progress bar

    //Event Handlers for Copy Operation
    RoboCopyCommands.OnFileProcessed += RoboSharpObject_OnFileProcessed; //This Increments an overall ProgressBar
    RoboCopyCommands.OnCopyProgressChanged += RoboSharpObject_OnCopyProgressChanged; //This Increments a per-File Progress Bar
    RoboCopyCommands.OnCommandCompleted += RoboSharpObject_OnCommandCompleted;
    RoboCopyCommands.OnProgressEstimatorCreated += RoboCopyCommands_OnProgressEstimatorCreated;

    //Start Copy Operation
    this.SetPauseResumeButtonState(true);
    RoboCopyCommands.ForEach(cmd => cmd.CopyOptions.MultiThreadedCopiesCount = 1);
    RoboCopyCommands.MaxConcurrentJobs = 1;                
    IRoboQueueResults RunResults = await RoboCopyCommands.StartAll();

    started = false;
    IsComplete = true;
    SetPauseResumeButtonState(true);