Background Worker




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;


namespace BarraProgreso_I
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            {
                for (int i = 1; i <= 100; i++)
                {
                    // Realizar una operación que consuma tiempo.
                    Thread.Sleep(50);
                    backgroundWorker1.ReportProgress(i);
                }
            }
        }




        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            {
                progressBar1.Value = e.ProgressPercentage;
                // Mostrar porcentaje progreso
                textBox1.Text = "Progreso: " + e.ProgressPercentage.ToString() + "%";
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.RunWorkerAsync();
        }


        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }


    }
}









https://msdn.microsoft.com/es-es/library/cc221403(v=vs.95).aspx
https://msdn.microsoft.com/es-es/library/system.componentmodel.backgroundworker(v=vs.110).aspx
https://msdn.microsoft.com/es-es/library/8xs8549b(v=vs.110).aspx
https://dotneat.wordpress.com/2010/03/06/ejemplo-backgroundworker-en-csharp/
https://www.dotnetperls.com/backgroundworker
https://www.codeproject.com/Articles/99143/BackgroundWorker-Class-Sample-for-Beginners
https://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx



No hay comentarios:

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.