In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What are the characteristics of the task parallel library in .NET 4.6? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a simpler and easier way.
In the upcoming .NET 4.6 release, some adjustments will be made to the task parallel library in .NET. This will include some new help methods to reduce the amount of code, and possibly performance optimizations. In addition, TPL will deal with a complex problem in the SetResult approach by using a new solution.
You can think of Task.FromResult as a typical template, and this function is used to create a completed Task object without first creating a TaskCompletionSource object. Developers cannot simulate this effect, so this requires access to the internal implementation of the Task type, and the above defects will be a hindrance if you want to achieve the same effect in exception handling.
.net 4.6 solves this problem through the Task.FromException method. Similar to FromResult, it bypasses the use of the TaskCompletionSource mechanism and avoids the consumption that comes with it.
A related feature is the Task.CompletedTask property, which returns a completed Task object, which in the current version can only be implemented through Task.FromResult (null). Strictly speaking, this feature is not necessary, but it does make the developer's intentions a little clearer.
The effects of these new features described above are negligible compared to the last important feature. A known behavior of the TaskCompletionSource.SetResult method is that if the subsequent methods of the method suspend the corresponding Task object, then these subsequent methods are likely to run synchronously. Stephen Toub explains to readers why this behavior may be problematic.
I have said that a possible result of calling methods such as {Try} Set* on TaskCompletionSource is that any synchronous subsequent methods of the Task object corresponding to the TaskCompletionSource object will run synchronously as part of the overall method call. If we call the SetResult method while holding the lock, then the synchronous subsequent methods of the Task object will run with the lock held, which can cause real problems. So, in the case of holding the lock, we need to set TaskCompletionSource to completed, but we don't actually finish it, but delay the completion until the lock is released.
To avoid this, developers can use the new tag RunContinuationsAsynchronously when creating a TaskCompletionSource:
Tcs = new TaskCompletionSource (TaskCreationOptions.RunContinuationsAsynchronously) this is the answer to the question about what are the features of the task parallel library in .NET 4.6. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 208
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.