16,022,896 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Bogomil Todorov 2024 (Top 8 by date)
Bogomil Todorov 2024
18-Jan-24 2:30am
View
Thank you very much!
Bogomil Todorov 2024
18-Jan-24 1:43am
View
Thank you very much, especially for the article "Switching From a BackgroundWorker To a Task - It's a Neater Solution, Particularly When Reporting Progress"!
Bogomil Todorov 2024
18-Jan-24 1:40am
View
"A picture is worth a thousand words!"
With the given example it is now clearer to me how to use the tasks and progressBars.
Thank you very much!
Bogomil Todorov 2024
17-Jan-24 8:39am
View
Yes, I can create int variable and increment it :-)
The problem is that this variable is not connected to progressBar. I'm sorry if I'm wasting your time. I still can't handle the issue.
Bogomil Todorov 2024
17-Jan-24 8:31am
View
var progressHandler = new Progress<int>(value =>
{
progressBar1.Value = progressBar1.Value + value;
});
var progress = progressHandler as IProgress<int>;
Task<datatable?>[] tasks = new Task<datatable?>[files.Count];
for (int currentTask = 0; currentTask < files.Count; currentTask++)
{
string file = files[currentTask];
tasks[currentTask] = Task.Run(() =>
{
DataTable? tbl = CSVtoDataTable(file);
progress.Report(1);
return tbl;
});
}
Task.WaitAll(tasks);
Bogomil Todorov 2024
17-Jan-24 7:08am
View
I'm beginner in tasks. So far I have always used BackgroundWorkers, but was informed that it is better to replace them with tasks.
Could you please give me more details or example how to do "So create a class level counter, zero it before your loop, and increment it in the Progress handler method."?
Bogomil Todorov 2024
17-Jan-24 6:38am
View
First thanks for the quick replies!
However, I still don't understand exactly how to do it. How to "Move the counter to the progress reporting code"?
Bogomil Todorov 2024
17-Jan-24 5:35am
View
Now I have tried the following, but still does not update progressbar:
IProgress<int> progress = new Progress<int>(value =>
{
progressBar1.Value = value;
});
Task<datatable?>[] tasks = new Task<datatable?>[files.Count];
for (int currentTask = 0; currentTask < files.Count; currentTask++)
{
string file = files[currentTask];
tasks[currentTask] = Task.Run(() =>
{
DataTable? tbl = CSVtoDataTable(file);
progress.Report(currentTask);
return tbl;
});
}
Task.WaitAll(tasks);
Show More