To give some context, I'm working on a Winforms application on .NET Framework 4.0. I need to call an internal service asynchronously without having to change the .NET Framework version or adding any Nuget packages. I'm familiar in using async/await but our current requirements doesn't allow for .NET framework upgrades
Asked
Active
Viewed 583 times
-2
-
5```Microsoft.Bcl.Async``` is literally the way to use async and await in .NET 4.0 Environments. I'm quite sure there's no other way apart from upgrading or using that nuget package. – devsmn Dec 18 '20 at 07:37
-
2In short you don't. You upgrade to a supported version of .net and make your life a lot easier. Though if you are really needing this in .net 4 depending on what you are doing there are likely ways – TheGeneral Dec 18 '20 at 07:38
-
2[Asynchronous programming patterns](https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/) - Use APM or EAP instead of TAP. – Alexander Petrov Dec 18 '20 at 07:38
-
2.NET 4.0 went out of support several years ago, and all .NET 4.x runtimes are binary replacements. Installing a newer version (eg through Windows Update) replaces the older one. I highly doubt there's *any* client machine still running .NET 4.0. Unless you want to target the also out-of-support Windows XP. – Panagiotis Kanavos Dec 18 '20 at 07:40
-
1So what's the actual question? It's not how to avoid Bcl.Async, because that's the only way to use async/await. Why are you targeting .NET 4.0 at all? – Panagiotis Kanavos Dec 18 '20 at 07:41
-
1`or adding any Nuget packages.` why? You can't even use .NET 4.0 without NuGet. Parts of the framework were extracted and published as separate NuGet packages. – Panagiotis Kanavos Dec 18 '20 at 07:42
-
@PanagiotisKanavos I'm supporting a winforms app that can't upgrade beyond .NET 4.0 just yet. – Raffy Dec 18 '20 at 07:45
-
6@Raffy that's not true - .NET 4.0 applications can upgrade to 4.5 easily. The only real blocking factor is Windows XP. And .NET 4.0 *requires* NuGet. BTW if you still use .NET 4.0 you can't use any site or service that uses HTTPS - almost everyone (certainly all the major services) moved to TLS1.2 4 years ago. .NET 4.0 has no support for TLS1.2 – Panagiotis Kanavos Dec 18 '20 at 07:47
-
@PanagiotisKanavos the application can't upgrade beyond .NET 4.0 as of the moment but it's already in our pipeline. Also the service to call is an internal service and we're minimizing any upgrades or breaking changes – Raffy Dec 18 '20 at 08:03
-
1@Raffy on the contrary, it can. For non-technical reasons though you decided not to. For non-technical reasons you decided to hobble .NET 4.0 by not using NuGet, which provides *necessary parts of the Framework*. This question is more about assumptions and prejudices than real technical problems. To really solve this, find out *why you assume* you can't use NuGet and solve this – Panagiotis Kanavos Dec 18 '20 at 08:06
-
@Raffy without Bcl.Async you can't use async/await, end of story. You *can* use Tasks and continuations (ie `ContinueWith`). That's thoroughly documented, although the docs went through a drastic reorganization in the last 10 years. – Panagiotis Kanavos Dec 18 '20 at 08:07
-
1Check [Chaining Tasks using continuation tasks](https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks) – Panagiotis Kanavos Dec 18 '20 at 08:10
-
1@Raffy as for not using NuGet, has the company thought of the legal implications of using unpatched libraries? Security fixes come out as new NuGet versions which means that by avoiding NuGet you deploy libraries with all of the vulnerabilities discovered in the last 10 years. – Panagiotis Kanavos Dec 18 '20 at 08:15
-
@PanagiotisKanavos it's our current project requirements to not make significant changes for now, but we're gonna do the upgrade eventually. Also, I should have used the term asynchronously in the title instead of async/await. What I don't understand is the downvotes for I'm only asking help on how to implement something – Raffy Dec 18 '20 at 08:20
-
1I didn't downvote but the question isn't good and frankly, has more to do with internal politics. Why not use that package? There's no technical reason. The real problem are developer misconceptions (that you can use .NET 4 without NuGet). As for continuations, they're thoroughly documented. That makes the current question even weirder - if you already use Tasks you must be using continuations already. – Panagiotis Kanavos Dec 18 '20 at 08:24
-
1I didn't DV, The downvotes are just people who can see the folly of trying to do this. Upgrading a project from 4 to 4.5 is very trivial with very few breaking changes (though they are there), the same with using a nuget. Also the question is a little vague, has unusual requirements, and no example of what you need to do. If you addressed these issues, the question would be fine IMO – TheGeneral Dec 18 '20 at 08:26
-
1"it's our current project requirements to not make significant changes"..ok so as has been mentioned already, that's not a technical reason. It's an arbitrary rule of the project to decide not to do something, even though a technical assesment would show little/no risk. So, there's nothing we can do for you in that situation. You already know what you need to do technically, just someone in your management has decided that you can't yet. So you have to tell them they must also delay using the async/await functionality until they change their mind and reassess their rules. – ADyson Dec 18 '20 at 08:29
-
1I was in a similar situation a few years ago, working for a *big* online travel agency - the team leader refused to upgrade because he was afraid of possible upgrade issues. Then airlines announced that only TLS1.2 would be used from 2016-01-01 onwards. That meant we either migrated or stopped selling. We had to migrate all everything in a month or so. No problems were caused by 4.5. – Panagiotis Kanavos Dec 18 '20 at 08:31
-
1In the meantime we had to deal with several issues *caused* by .NET 4.0 problems that were solved in 4.5, some of them production-stoppers. Airline SOAP messages are *big* so when you make 1M request per day, you can easily run into any XML Serializer concurrency bugs. One of them, that was fixed in 4.5, would cause corruption to XmlSerializer's internal type cache under certain conditions, crashing one server, then the next in a cascade that **brought down 70 servers**. We had to **wait 2 years to apply the fix we knew existed** because of someone's arbitrary decision not to upgrade – Panagiotis Kanavos Dec 18 '20 at 08:38
1 Answers
2
In short: It won't work without it.
Answered here: async/await keywords not available in .net 4.0
Workaround here: How can I use the async keywords in a project targeting.net 4.0

Nathaniel Walser
- 206
- 2
- 9
-
Well, it is impossible to use the specific keywords async/await with .NET 4.0 without the package. I don't say it is impossible to archieve something similar with any other package. But yeah, i get the point, its not quite satisfying if you recieve: Its not possible as an answer. – Nathaniel Walser Dec 18 '20 at 08:10