Click here to Skip to main content
15,885,186 members
Everything / TPL

TPL

TPL

Great Reads

by Mohammad Elsheimy
SynchronizationContext class and how it affects code behavior in action, and a look at Task.ConfigureAwait()
by Manish Gupta .Net
How to use TPL dataflow for reading files and inserting to database
by Stephen Marcus
Replaces events and any other async void cases with awaitable Task signatures.
by Marco-Hans Van Der Willik
This article explores the performance, scalability and limitations of the various .NET Threading Implementations.

Latest Articles

by Marco-Hans Van Der Willik
This article explores the performance, scalability and limitations of the various .NET Threading Implementations.
by Mohammad Elsheimy
SynchronizationContext class and how it affects code behavior in action, and a look at Task.ConfigureAwait()
by Stephen Marcus
Replaces events and any other async void cases with awaitable Task signatures.
by Marc Clifton
A discussion of various approaches to threading, covering locks, mutexes, semaphores, concurrent collections, work queues, threads, PLINQ, TPL, exception handling, and cancellation tokens

All Articles

Sort by Score

TPL 

28 Aug 2021 by Mohammad Elsheimy
SynchronizationContext class and how it affects code behavior in action, and a look at Task.ConfigureAwait()
8 Dec 2017 by Manish Gupta .Net
How to use TPL dataflow for reading files and inserting to database
15 Mar 2016 by RickZeeland
Here is a good article by Stephen Cleary: Async/Await - Best Practices in Asynchronous Programming[^]But I'm afraid he says what you don't want to hear:Quote:As you convert synchronous code to asynchronous code, you’ll find that it works best if asynchronous code calls and is called by...
12 Aug 2014 by Simon_Whale
you could set the MaxDegreesOfParallelism[^] option in your Parrallel.For loop.Alternative options I could suggest is look at the Threadpool Class as you are also able to limit the number of threads that it manages.ThreadPool.SetMaxThreads[^]
30 Oct 2014 by OriginalGriff
You can't really do that, not without complicating things far beyond sensible levels: the generic Dial class shouldn't know that any form related (or other user interface detail) classes even exist, much less what they contain.Instead, your Dial class should create an event which the form...
4 Oct 2015 by Wendelius
The purpose of MaxDegreeOfParallelism is only to restrict how many threads can be used in maximum. It doesn't meant that the system will use s many threads. The decision how many threads are used is done by the TaskScheduler[^]. You can either stick with the default scheduler or create your...
18 May 2016 by Richard Deeming
The ProgressBar control[^] has built-in support for showing indeterminate progress - just set the Style property[^] to ProgressBarStyle.Marquee:oi1ProgressStatus.Style = ProgressBarStyle.Marquee;await Task.Run(() =>{ BaseParameters.ErrorBag.Clear(); if...
10 Oct 2014 by KenBonny
I want to make a timer app where various timers are started asynchronously and then update the ui with each tick. (I'm doing this to learn the TPL library). But for some reason my code seems to hang.I have three layers. The first is my WPF program, when I click on a button, I can create a...
12 Dec 2016 by Jon McKee
1) A thread pool is just a convenient thread manager. It increases and decreases the number of threads it uses based on load and can re-use threads to negate some overhead. It also keeps idle threads alive to further improve performance for repeated quick-running tasks. The maximum number of...
15 Feb 2018 by Patrice T
Quote: PK 'PK' is an hint that the file is compressed, ZIPed. So, first step is to try to unzip the file.
3 Mar 2019 by James Walsh Jr
First of all here is the link to the docs for the Task Parallel library. This would be a good place to start with such a very generic question. You should probably examine using a threadpool and setting the maximum threads in the thread pool. // Limit threadpool size int workerThreads,...
3 Mar 2019 by Graeme_Grant
According to the documentation, the Task Parallel Library (TPL)[^], "...handles the partitioning of the work, the scheduling of threads on the ThreadPool[^]". And according toThreadPool[^] documentation, "There is one thread pool per process. Beginning with the .NET Framework 4, the default...
18 Dec 2023 by Graeme_Grant
Your code is "polling" for a state change using a timer. You should be listening for an event from your DLL. Gerry has mentioned the Event pattern. This is core to .Net, in fact you are using it with the timer, the timer raises an event that you...
7 Jun 2012 by shoukhatkhan
Hi,I have an application in C# 2010 and .Net 4.0 which uses multi threading through Task Parallel Library. There are some static classes and static methods within this. Whenever a static method is run in a single thread the performance is as expected but when the same method is called by...
7 Jun 2012 by Tim Corey
The simple answer is no, static classes and methods will not get slower when run on multiple threads. They really cannot. However, that doesn't mean that the resources they access won't run slower. For example, if each thread is downloading a file and the combined number of threads maxes out...
7 Jun 2012 by Dave Kreskowiak
No, it doesn't. But, whatever you're using for a data store might not appreciate it.I'm not about to go digging through that pile of code to find it either. My head exploded when I saw that. I think you REALLY need to try and break that down into smaller methods. You may find out that...
11 Aug 2013 by KenBonny
I found the solution. (Took me a while too.)What I did wrong, was awaiting the Task.Factory.StartNew, making the thread wait for something that would never stop and thus hang the application. The solution in code: public void Start() { if (IsStarted)...
2 Jan 2014 by Rob Philpott
A very good morning to all.I want to check I'm not missing something. I'm looking at a lot of code which is following the pattern of kicking a task off, then in a continuation there is a call to wait on the task being continued from (the antecedent, to be a good M$ citizen).This seems...
3 Jan 2014 by firas sawaf
It does look odd, though the explanation below the code may shed some light:"Because a console application may terminate before the continuation task executes, the WaitAll method is called to ensure that both the original task and its continuation finish executing before the example...
22 Apr 2014 by Faisalabadians
public List GetAll() { List customers = new List(); db.Customers.ToList().ForEach(customer => { customers.Add(new CustomerModel() { ...
12 Aug 2014 by Rob Philpott
I've got 4000 things to do in a loop, and I'd like to do some of them at the same time. I believe Parallel.For scales to the number of cores which on our server is 48. I don't want that many running at the same time as they open network connections etc. and I have a feeling things couldn't...
12 Aug 2014 by OriginalGriff
I'd divide the 4000 objects into five lists of objects, and hand each list to a separate BackgroundWorker to process.
12 Aug 2014 by MonsterMMORPG
Alright there are so many questions and answers on thisBut at the latest tech (.net 4.5 visual studio 2013 v3) , C# WPF applicationWhat is the best (the one that has most performance, the one that you have most control over everything, the one that works perfect as a TASK from...
2 Sep 2014 by KergalBerlin
Hi community,I am new to parallel coding and have some trouble understanding what I have read about it. Let's assume the following scenario: I have 5 tables in a sql server and I receive data from source X which needs to be filtered,sorted and validate and the resulting string[][]...
3 Oct 2014 by zhshqzyc
I have an application with producer-consumer pattern. Because I am not strong on TPL, so I made a simple test class to do it.Basically in the producer method, I added 100 number to the queue then print them in consumer. The code is straightforward. using System;using...
6 Oct 2014 by Member 11133146
HiSo I am new to programming using the .Net TPL Framework and multi-threading in general. I have googled up some tutorials and articles and put together the solution below. It is a simple multithreaded queue and a scheduler that polls the queue and processes each item as a seperate...
28 Nov 2014 by gunmeets
I have written an application to see how we can use tasks.I am starting 50000 tasks in one go with minimum thread pool set to 32500 ( which is the limit for a 64 bit application) and inserting a record into db in the function with a sleep of 5 sec.If I set the min. thread pool to 8000...
28 Nov 2014 by Mehdi Gholam
There are many reasons:1) What "db" are you using and the performance characteristics of that engine.2) Resource/object contention between your threads/tasks3) The amount of data being savedAs a side note my RaptorDB - The Key Value Store V2[^] can handle 400,000 writes/sec on an i7...
8 Dec 2014 by Santiago Fabian
Protected void Page_Load(object sender, EventArgs e){ XDocument response = ThirdPartyAPI.HttpRequest(someParams); if(response != null) { var node = response.Root.Elements("documents").Elements("document"); string url =...
8 Dec 2014 by Assil
Looks to me that ThirdPartyAPI.HttpRequest is asynchronous method, in which case there should be some method or property in ThirdPartyAPI that indicates whether the HttpRequest is still busy or done..and that very API could be used in lieu of if(response != null)Can you look into that?
9 Feb 2015 by #realJSOP
I'm starting to dabble in the TPL, and I'm looking for comments regarding the code to see if there's something I'm missing. It seems to work, but I can't find any decent intros to the subject. The following is what I've managed to glean from Google.The tasks I'll eventually be creating will...
9 Feb 2015 by Veronica S. Zotali
so smtg like that won't do ?private void ProcessRequests(IList requests){ var observer = observers.First(); var task = new Task(() => requests.ToList().ForEach(ProcessRequest)); task.Start(); task.ContinueWith((con) => ...
9 Feb 2015 by Richard Deeming
You're currently calling the new Task(Action, object, CancellationToken) constructor; the TaskCreationOptions you're passing in are ignored, because they're being treated as the state parameter to the action parameter.You should generally try to avoid creating tasks which aren't...
13 Apr 2015 by ammad88
How can I add "show more links tab" after showing 10-15 links instead of showing 100-200 links? I want to show only 10-15 links at first and then when somebody clicks show the rest of the hidden links to save page space.{if $listing_styles.links}
21 May 2015 by vinayvraman
Hi All,I have a question regarding cancellation of tasks. Please read below for the explanation. Any suggestion would help me solve the problem.I have 3 tasks. Lets call them task1, task2, & task3. Each of them are independent except for the data. i.e. task1 puts data into a queue1 and...
22 May 2015 by Mathi Mani
Hi,What you are trying to do can be done. But it cannot be answered in this quick answers section. It is a pretty vast topic. Here are some articles that help you understand the concept and implement a solution.Process task based on the outcome of the previous...
15 Jun 2015 by anurag.netdeveloper
Hi Using TPL i am able to consume all cores of my machine, but sometimes the CPU usage reached to 100%. My question is how can we forcefully tell to program the terminate the all threads which are currently using and reset the task again. Below is my program - Parallel.For(0,...
4 Oct 2015 by Member 11266633
I set number of thread 10, but it works in 3 threads.(I have triple-core processor)Parallel.ForEach(list,new ParallelOptions { MaxDegreeOfParallelism = 10 }, () => Thread.CurrentThread.ManagedThreadId, (i, loopState, threadId) => { ...
9 Oct 2015 by Russian Clients
I am using BroadcastBloc and have few ActionBlocks Linked to my object. I want to manage behaviour of my object and if there no one is linked to my BroadcastBlock it will stop broadcasting. WHile debug i can see "LinkedTargets" property but cannot access it from code.What can i do enstead ?
20 Oct 2015 by virang_21
I need to update Geocode information in database which I am doing via calling Google MAPs API. To speedup the process I would like to use Parallel.ForEach on database query and then add the results to list of objects which I have done. I have two questions.1. Is it OK to call...
19 May 2016 by George Swan
Here's the basic idea, you may have to adapt it to your needs. Don't try to martial threads yourself, that is only necessary with legacy code. The async await keywords provide sufficient abstraction for you not to have to do that.//This is the button click event handler//note the async...
12 Nov 2016 by Member 11266633
I have two lists.var proxy = new List(); // 4 proxiesvar urls = new List(); // 100 urlsI want that every proxy make 25 requests with urls. How separate it equality between threads?What I have tried:I try use Partitioner.Create, but cannot understand how separate...
10 Dec 2016 by Er. Dinesh Sharma
Hi Experts,I am using .NET Framework 5.0 and using Task Parallel Library (TPL).I have some confusion in Managed Thread Pool which TPL Use.1)How many thread pool in machine having 4-Core Processor.?Is thread pool count depended on Operating System or Processor or Application ?2)When we...
6 Jul 2017 by usmanali.ali843
I am running my tasks for maxdegreeofparallelism using parallel.foreach and if there's a task taking too long time to complete then all have to wait for next iteration process. Now, the scenario is, I have mutiple file orders processing performed by my windows service and on first phase I fetch...
6 Jul 2017 by RickZeeland
When doing I/O operations, it is not a good idea to use parallel processing, most of the time this will slow things down, especially when a harddisk is being used. With newer SSD's or RAID it might work, however I would not recommend it.
4 Sep 2017 by niranjankala
I have a list of predefined regex pattern strings (around `7 thousand` type of regex pattern to group similar type of messages). Now I have two set to list one for `regex patterns` and another for `real messages` which contains some variable names. I need to group all the similar messages...
4 Sep 2017 by Graeme_Grant
List warningKBErrors = distinctKBErrors.Where(kbErr => kbErr.ErrorType == "Warning").ToList(); List fatalKBErrors = distinctKBErrors.Where(kbErr => kbErr.ErrorType == "Fatal").ToList(); List severeKBErrors = distinctKBErrors.Where(kbErr => kbErr.ErrorType ==...
5 Nov 2017 by NickResh777
I have a question on how to properly adapt generic Action delegates to simple non-generic version of Action delegate. I have a piece of code. I wish you could point to my errors or advise some other way to implement. I do have a doubt over capturing context of method arguments public static...
5 Nov 2017 by Graeme_Grant
I'll do one of your method calls for you... you need to tell the Action what to expect, just like the method wrapper: public static Action AdaptToRootAction(Action action, T1 arg1, T2 arg2) { T1 param1 = arg1; T2 param2 = arg2; return delegate { // pass...
15 Feb 2018 by phil.o
This is not a text file, so Notepad++ is not the right tool. A binary file viewer would allow you to see the binary content, but I'm not sure you can get useful informations from that.
16 Apr 2021 by Stephen Marcus
Replaces events and any other async void cases with awaitable Task signatures.
15 Dec 2023 by Jared THompson
Hi, new to C#, very new to programming for WPF. I want to cause an indicator on the MainWindow to change based on the output of a DLL. The program needs to be continuously aware of the behavior of the DLL, think of it as a streaming data...
11 Jul 2023 by Marco-Hans Van Der Willik
This article explores the performance, scalability and limitations of the various .NET Threading Implementations.
2 Aug 2018 by Marc Clifton
A discussion of various approaches to threading, covering locks, mutexes, semaphores, concurrent collections, work queues, threads, PLINQ, TPL, exception handling, and cancellation tokens
3 Sep 2012 by Christopher Diggins
An informal survey of implementation techniques of the map higher-order function for arrays in C#.
24 Jan 2012 by Karl Sanford
Removing noise from the Kinect Depth Frames in real-time using pixel filters and weighted moving average techniques.
9 Feb 2015 by Veronica S. Zotali
Real example that shows how to implement Observer pattern using IObservable and IObserver
26 Aug 2015 by Clifford Nelson
If you are having issues with getting the WPF Focus() method working, then maybe all you need to do is add a delay on the Initialized event before setting the focus. This solution is a nice demonstration of the features of TPL, and how easy TPL can make doing asynchronous programming in the UI.
9 Aug 2016 by Rasik Bihari Tiwari
Let's understand the evolution from older multi-threading world to Task Parallel library (alias TPL). What are the use cases where you would want to leverage TPL instead of creating threads on your own. What are exact areas where TPL has real edge.
2 Dec 2013 by Gary Owsiany
Keeping a WPF application responsive involves using background processes to handle long running tasks, and the TPL makes this programming task easier than ever. It also provides a way to cancel the task asynchronously and to update the UI (for example, with a progress bar) from the background proces
2 Aug 2017 by Richard Deeming
Adding cancellation support to the SendMailAsync method
12 Nov 2013 by John Pravin
Asynchronous Programming with Task Parallel Library.
31 Jan 2013 by Garrett M. Groff
Random data/password generator using WPF and MVVM to accomplish clean separation of GUI logic and business logic using MVVM pattern.
15 Mar 2016 by Patrick Skelton
Hi,I know the internet is littered with fragments of information on this subject, but none of them seems to provide a clear explanation of how you incorporate async functions into synchronous code.I seem to be caught between a rock and a hard place. I have to call an API that provides...
5 Feb 2013 by db7uk
Hi,I like what you have done however personally I feel the mix of custom thread management plus mangeing TPL tasks etc very problematic in this instance. TPL has many great features that do not require all the custom management.Whilst I have not tried executing tasks in order of thread...
8 Aug 2013 by Manas Bhardwaj
Haven't used BackgroundWorker since .Net 2.0, but I guess it would have only improved. You might want to have a look at it.http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^] Look at this article as...
2 Sep 2014 by kbrandwijk
You have a string[][]:string[][] myArray = new string[][] {};You can either use one method for all tables, or define a separate method for each table.Using one method for all tables, you define a list of tablesList tables = new List { "table1", "table2", "table3",...
30 Oct 2014 by zhshqzyc
In my MainWindow, I have public partial class MainWindow : Window { public List activeChannels = new List();In my custom class, public class Dial { public ChannelResource m_ChannelResource; public VoiceResource...
7 Apr 2016 by Richard Deeming
Calling any of the TrySet... methods on a TaskCompletionSource which is already in a final state won't cause any problems. That's what the TrySet... methods are there for. :)If the source task accepts a CancellationToken, you could alternatively use the...
10 Apr 2017 by Swapnil Dhage
This is a helper/utility class that will add a layer of abstraction as well as separation for dispatcher related operations in WPF.
1 Mar 2013 by essence
Local scope delegates and Lambda expressions allow for some very smart and useful utility functions.
19 May 2016 by SURAJ-CDAC
In my project I want to show the Marquee style progress bar. where I had a form on which there is a toolbar containing a button. On the click of that button I call a webservice. Till webservice call returns I want to show the Marquee progress bar which is on modal dialog.How I can...
22 Jan 2015 by S'Aditya
Values are of stiring type. and after the end of string it is having a blank space
29 Jul 2014 by ankurtrue1
I have a requirement, such that I need to do some synchronous processing within a parallel execution flow.I have some tasks working within a Parallel foreach. Now what I need to do is that, in between do some database updates. Which I do not want to be done using async and await, since this...
6 Oct 2014 by zhshqzyc
The problem is that your app is exiting before it gets a chance to run. You're waiting on the first task to complete so as soon as that occurs (which is near instant) then the app exits. If you change the logic to wait for the last task to complete (c) then you'll block until all the work is...
15 Feb 2018 by Member 13680563
Hello Could anyone tell me if I can make the contents of this .TPL file readable with notepad? If so how? Any help greatly appreciated! Thanks PK  êŠZJýMç!U Š template.xml³)IÍ-ÈI,Iµãåâ´IËÌI-±8mŠ R“3sÀˆ„]QjqLNn±^V±>X ¬PI%Dl‚MJbI¢KfQjrI~Q%H¯>ª/—>’í PK  3|&K6îêøc~ ú”...
5 Feb 2013 by essence
I've reviewed the QueuedTaskScheduler and I'm very confused.http://blogs.msdn.com/b/pfxteam/archive/2010/04/09/9990424.aspx[^]So I wrote this class to do what I wanted.What I wanted is a class that will queue up tasks in the background and start them in order with a lower priority. Also...
3 Oct 2014 by pietvredeveld
Hi,Spending more time in the consumer will not bring you to a solution. The problem is that you tell the queue to Complete before all Consumers are ready.The call to m_Queue.Complete() signals to the IDataflowBlock that it should not accept nor produce any more messages nor consume any...
15 Feb 2015 by Gaurav_Chaudhary
You can use "Async" and "Await" keywords ,if it's C# 4.5 or above.. Check this out https://i-msdn.sec.s-msft.com/dynimg/IC612215.png[^]Thanks
7 Apr 2016 by Patrick Skelton
Hi,I am trying to implement the Microsoft recommended way to add a timeout to a Task. The details are here: MSDN Blogs[^]It all seems to be working okay except for one thing. When the timeout triggers, I get inside the MarshalTaskResults() function and find that the status of the...
3 Mar 2019 by Manisha Tambade
I want to know number of threads created using TPL? What I have tried: Checked degree of parallelism.