Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 35736

Raw threads and async lambdas

$
0
0

Senior Consultant, Ben Williams shares some suggestions on avoiding unexpected behaviors with async/lambdas


Using async methods/lambdas where they are not expected causes unexpected problems. The typical example I discuss with people is TaskFactory.StartNew() because it’s an easy way to create Tasks and some people reach for that instead of Task.Run(), but I recently came across some code hitting the same problem while creating threads the traditional way.

In this scenario, the code was intended to create some child threads that poll a resource. That resource would sometimes be changed and the master thread would Abort() the child threads and create new ones polling the new resource. But there was a thread leak. Sometimes threads could continue to run after they should have been aborted.

 

Read the full post on Ben’s blog


Viewing all articles
Browse latest Browse all 35736

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>