Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

MrVinc

ProgressBar update

Hello,
I upload files via SCP and want to see the status in a ProgressBar.
How did I update the ProgressBar?

Here my code for the upload with a BackgroundWorker:
private void frm_main_Load(object sender, EventArgs e)
{
    worker = new BackgroundWorker();
    worker.WorkerReportsProgress = true;
    worker.WorkerSupportsCancellation = true;
 
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
}
 
private void btn_hochladen_Click(object sender, EventArgs e)
{
    worker.RunWorkerAsync(2000);
}
 
void worker_DoWork(object sender, DoWorkEventArgs e)
{
    if (arguments.Length > 1)
    {
        for (int i = 1; i < arguments.Length; i++) // Loop through array
        {
            using (Session session = new Session())
            {
                // Connect
                session.Open(sessionOptions);
 
                // Upload files
                TransferOptions transferOptions = new TransferOptions();
                transferOptions.TransferMode = TransferMode.Binary;
 
                TransferOperationResult transferResult;
                string path = "/recalbox/share/roms/" + folder + "/";
                transferResult = session.PutFiles(@"" + String.Join(", ", arguments[i]), path, false, transferOptions);
                //transferResult = session.PutFiles(@"" + String.Join(", ", arguments[i]), "/recalbox/share/test/", false, transferOptions);
 
                // Throw on any error
                transferResult.Check();
 
                // Print results
                //foreach (TransferEventArgs transfer in transferResult.Transfers)
                //{
                //    MessageBox.Show(transfer.FileName);
                //}
            }
        }
    }
}