C# Tutorial - BackgroundWorker | FoxLearn
ฝัง
- เผยแพร่เมื่อ 21 ก.ย. 2024
- 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#
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.
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();
}
}
}
Thank you so much.
You sound like a robotic trainer.
and you can code any project in two or three days.
Thank you. I don't have recording studio :(
Works great! Yet again another a great tutorial! love u pce
Thank you so much !
It was very usefull for me. Thank you.
Thank you !
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.
+TheWolverine1984 Hi, What's your email ? I can send to you sample code. thanks
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 :)
+Fox Learn Please post the example code.
Please where will I place my c# sql saving code that will save data to mssql database whiles the progress bar is loading
How you made your title of the form in center of the title bar
thanks,helped❤
THANK YOU! I got stuck by using ThreadPool which fucked up my whole application
backgroundWorker.ReportProgress(index++ * 100 / Processo, string.Format("Proceso data {0}", i));
In this line the sign is multiplication?
tank you so much ... you are wonderfull
This BackgroundWorker states that it doesn't report progress. Modify WorkerReportsProgress to state that it does report progress.'
Great 👍👍👍
Pro trick: watch movies at Flixzone. I've been using them for watching all kinds of movies lately.
@Forest Braylen Yup, been using Flixzone} for since november myself :)
is there a way to make a pause button with backgroundWorker?
Yes, I'll upload soon !
@@foxlearn oh much thx! because i can't find a right decision
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)
very good
Thank you !
i want splash screen says saved!! after saving data..Could you pls try this on button click event.
Did you get this tutorial...? If you did forward me the link... Thanks
Still blocks the UI ???
What do you mean?
How it's possible!!!, people asking for code to email.... hmm thats pathetic!!
You can find sourse in my channel
wow robot, i like robot
Thank you
Why the robot voice????
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
n...
doesnt works
Please check your code again
too slow how can make it more faster?
It's only a demo, you can show progress bar base on your data process. remove Thread.Sleep
@@foxlearn then inside the *if* statement in the for loop i can put a method that is saving a data into the database?
Too much code, too little explanation. This channel is not for me. Unsuscribing
:(
come back!
This code does not work
Have a try mine code on my channel.
Just use your voice ffs, If i wanted this shit i'd ask siri.