C# Tutorial - BackgroundWorker | FoxLearn

Sdílet
Vložit
  • čas přidán 20. 06. 2015
  • 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.
    c# background worker
    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
    BackgroundWorker using C#
    MultiThreading Using a Background Worker, C# CodeProject
    Backgroundworker example 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#

Komentáře • 62

  • @NoOne-wf6hm
    @NoOne-wf6hm Před 3 lety +2

    What I really didn't get it was how to get an Argument Object to Assign to BackgroundWorker.
    Where/How would One get the Argument object from?
    Taking a few Examples into Consideration for the Sake of Understanding:
    - SQL Data Transactions;
    - Copying Several Files;
    - Incoming Text (Like Chat Application)
    How could One Implement this?
    Besides that:
    - The structure part was slightly new to me (I need to get used to it). Was a nice example on how to implement something different in my applications (I never saw a professional C# Application).
    - I believe the Tutorial could've had a simpler way for Newbies to understand how Background Worker works before they complain here (for me while organizing my own way; it was quite simple to understand). I think I finally got to understand how BackgroundWorker Works (Thankful for that).
    1st Things Last:
    Overall: Superb Tutorial!
    Thank you Buddy.

  • @companionpuppy7539
    @companionpuppy7539 Před 5 lety +1

    Works great! Yet again another a great tutorial! love u pce

  • @tanveerkit
    @tanveerkit Před 7 lety +2

    Thank you so much.
    You sound like a robotic trainer.
    and you can code any project in two or three days.

    • @foxlearn
      @foxlearn  Před 7 lety

      Thank you. I don't have recording studio :(

  • @raybammm
    @raybammm Před 9 lety

    tank you so much ... you are wonderfull

  • @tomd5678
    @tomd5678 Před 4 lety +5

    namespace BackgroundWorkerExample
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    struct DataParameter
    {
    public int Process;
    public int Delay;
    }
    private DataParameter _inputparameter;
    private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
    progress.Value = e.ProgressPercentage;
    lblPercent.Text = string.Format("Processing...{0}%", e.ProgressPercentage);
    progress.Update();
    }
    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
    int process = ((DataParameter)e.Argument).Process;
    int delay = ((DataParameter)e.Argument).Delay;
    int index = 1;
    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 length of operation
    //Add your code here
    }
    }
    }
    catch (Exception ex)
    {
    backgroundWorker.CancelAsync();
    MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }
    private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
    MessageBox.Show("Process has been completed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    private void btnStart_Click(object sender, EventArgs e)
    {
    _inputparameter.Delay = 100;
    _inputparameter.Process = 1200;
    backgroundWorker.RunWorkerAsync(_inputparameter);
    }
    private void btnStop_Click(object sender, EventArgs e)
    {
    if (backgroundWorker.IsBusy)
    backgroundWorker.CancelAsync();
    }
    }
    }

  • @ElonMuchen3737
    @ElonMuchen3737 Před 4 lety

    It was very usefull for me. Thank you.

  • @tharinduchamara8330
    @tharinduchamara8330 Před rokem

    thanks,helped❤

  • @juancarlosalonsogonzalez6359

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

  • @raziahmad2376
    @raziahmad2376 Před 4 lety

    Great 👍👍👍

    • @forestbraylen2758
      @forestbraylen2758 Před 3 lety

      Pro trick: watch movies at Flixzone. I've been using them for watching all kinds of movies lately.

    • @caspianrobert7327
      @caspianrobert7327 Před 3 lety

      @Forest Braylen Yup, been using Flixzone} for since november myself :)

  • @gideonowusu9148
    @gideonowusu9148 Před 2 lety

    Please where will I place my c# sql saving code that will save data to mssql database whiles the progress bar is loading

  • @TheWolverine1984
    @TheWolverine1984 Před 8 lety +1

    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.

    • @foxlearn
      @foxlearn  Před 8 lety

      +TheWolverine1984 Hi, What's your email ? I can send to you sample code. thanks

    • @TheWolverine1984
      @TheWolverine1984 Před 8 lety

      Fox Learn Hello! I think it would be better if you put int in pastebin.com/ for example (like this: pastebin.com/17a66dXg) and make the link available in the description so everyone could see it and not just me :)

    • @eviscero
      @eviscero Před 8 lety +1

      +Fox Learn Please post the example code.

  • @diepthihuongduong1125
    @diepthihuongduong1125 Před 5 lety

    very good

  • @nishantjadhav6730
    @nishantjadhav6730 Před rokem

    How you made your title of the form in center of the title bar

  • @Juznik1389
    @Juznik1389 Před 2 lety

    THANK YOU! I got stuck by using ThreadPool which fucked up my whole application

  • @plumemotorpartpmp1625

    This BackgroundWorker states that it doesn't report progress. Modify WorkerReportsProgress to state that it does report progress.'

  • @jamesthankachan3036
    @jamesthankachan3036 Před 6 lety +1

    i want splash screen says saved!! after saving data..Could you pls try this on button click event.

    • @olamas92
      @olamas92 Před 4 lety

      Did you get this tutorial...? If you did forward me the link... Thanks

  • @DimaProsto
    @DimaProsto Před 4 lety

    is there a way to make a pause button with backgroundWorker?

    • @foxlearn
      @foxlearn  Před 4 lety

      Yes, I'll upload soon !

    • @DimaProsto
      @DimaProsto Před 4 lety

      @@foxlearn oh much thx! because i can't find a right decision

    • @DimaProsto
      @DimaProsto Před 4 lety

      i did it, but if i click pause button and then cancel button my .exe only changes a text of start button like i want but cancel doesn't work. But if i press cancel button when start button is activated (thread running, not on pause) it works perfect. (i used for pause and continue of threads manualresetevent)

  • @jessjane7908
    @jessjane7908 Před 7 lety

    wow robot, i like robot

  • @SupunNimantha
    @SupunNimantha Před 4 lety

    Still blocks the UI ???

  • @guillermoboh8479
    @guillermoboh8479 Před 6 lety +3

    How it's possible!!!, people asking for code to email.... hmm thats pathetic!!

    • @XpucT
      @XpucT Před 6 lety

      You can find sourse in my channel

  • @kevinlin6937
    @kevinlin6937 Před 7 lety

    n...

  • @deltekkie7646
    @deltekkie7646 Před 3 lety

    Why the robot voice????

    • @foxlearn
      @foxlearn  Před 3 lety

      Because I don't have enough money to build a recording studio, buy equipment. My area is on the national highway, it's quite noisy. almost impossible to record

  • @Inyector
    @Inyector Před 4 lety

    doesnt works

    • @foxlearn
      @foxlearn  Před 4 lety

      Please check your code again

  • @nelsonalva
    @nelsonalva Před 7 lety +7

    Too much code, too little explanation. This channel is not for me. Unsuscribing

  • @redenrodriguez966
    @redenrodriguez966 Před 5 lety +1

    too slow how can make it more faster?

    • @foxlearn
      @foxlearn  Před 5 lety +2

      It's only a demo, you can show progress bar base on your data process. remove Thread.Sleep

    • @redenrodriguez966
      @redenrodriguez966 Před 5 lety

      @@foxlearn then inside the *if* statement in the for loop i can put a method that is saving a data into the database?

  • @jirisimecek3216
    @jirisimecek3216 Před 6 lety

    This code does not work

    • @XpucT
      @XpucT Před 6 lety

      Have a try mine code on my channel.

  • @thebigvrguy4571
    @thebigvrguy4571 Před 6 lety

    Just use your voice ffs, If i wanted this shit i'd ask siri.