C# Tutorial – BackgroundWorker | FoxLearn

32
1



How to use a Background Worker in C# step by step. The C# Basics beginner course is a free C# Tutorial Series that helps beginning programmers learn the basics of the C# Programming Language. This is the best way to Learn C# for beginners

c# background worker
background worker c#
How to: Use a Background Worker – MSDN
BackgroundWorker Class example in windows forms application
C# BackgroundWorker and ProgressBar with Cancellation
C# BackgroundWorker Tutorial
c# – how to use a backgroundworker
C#: Simple BackgroundWorker example
BackgroundWorker using C#
How to: Use a Background Worker
BackgroundWorker Class Sample for Beginners
MultiThreading Using a Background Worker, C# CodeProject
Backgroundworker example c#
Using The BackgroundWorker In C#
Understanding C#: BackgroundWorker tutorial for multithreaded GUI
Multi-threading with the BackgroundWorker
Using the BackgroundWorker Component in C#
Background Worker Class C#
Using a BackgroundWorker: progress changed and completed
Working with Background Workers in C#

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

32 COMMENTS

  1. For a much more realistic voice, try animaker voice, it has 5 free downloads per month for one account.. but u can make 10 accounts…:-)

  2. It's necessary to say that the BackgroundWorker properties: WorkerReportsProgress and WorkerSupportsCancellation must be set on TRUE.
    And a recommendation: To prevent the message "operation completed" when user cancel, maybe you can modifiy the RunWorkerCompleted event:
    MessageBox.Show(this.pgbProgreso.Value == 100 ? " Operation completed." : "Partially completed.");

    Excellent material, thanks.

  3. backgroundWorker.ReportProgress(index++ * 100 / Processo, string.Format("Proceso data {0}", i));
    In this line the sign is multiplication?

  4. Code –>
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApp1
    {
    public partial class Optimização : Form
    {
    public Optimização()
    {
    InitializeComponent();
    }

    struct DataParameter
    {
    public int Process;
    public int Delay;
    }

    private DataParameter _inputparameter;

    private void progressBar1_Click(object sender, EventArgs e)
    {

    }

    private void btnStart_Click(object sender, EventArgs e)
    {
    if (!backgroundWorker.IsBusy)
    {
    _inputparameter.Delay = 100;
    _inputparameter.Process = 1200;
    backgroundWorker.RunWorkerAsync(_inputparameter);
    }
    }

    private void lblPercent_Click(object sender, EventArgs e)
    {

    }

    private void Optimização_Load(object sender, EventArgs e)
    {

    }

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
    int process = ((DataParameter)e.Argument).Process;
    int delay = ((DataParameter)e.Argument).Delay;
    int index = l;
    try
    {
    for (int i=0;i<process; i++)
    {
    if (!backgroundWorker.CancellationPending)
    {
    backgroundWorker.ReportProgress(index++ * 100 / process,.string.Format("Process data {0},i"));
    Thread.Sleep(delay);//used to simulate lengh of operation
    //Add your code here
    //…
    }
    }
    }
    catch (Exception ex)
    {
    backgroundWorker.CancelAsync();
    MessageBox.Show(ex.Message, "Message", MessageBoxButtons, OK, MessageBoxIcon.Error);
    }
    }

    private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
    progress.Value = e.ProgressPercentage;
    lblPercent.Text = string.Format("Limpando…{0}%", e.ProgressPercentage);
    progress.Update();
    }

    private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
    MessageBox.Show("Limpeza Terminada.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void btnStop_Click(object sender, EventArgs e)
    {
    if (backgroundWorker.IsBusy)
    backgroundWorker.CancelAsync();
    }
    }
    }

  5. Hi, good morning please can you send me the code in to my email address this is my mail address kishanr.khamitkar@gmail.com

  6. ok, i made it work properly now! you must call the backgroundworker doWork from the end part of the click method like this:

    backgroundWorker.RunWorkerAsync(_inputparameter);

    also, using ftp://192.168.. ip format wasnt working for me but ftp://this.this.com/files

  7. Thanks! A small note, it would be much more helpful if you gave a link to the sample code you are using in the video.

LEAVE A REPLY

Please enter your comment!
Please enter your name here