troubleshooting Question

Can a Task.Run().Wait() task end up being "inlined"?

Avatar of deleyd
deleydFlag for United States of America asked on
.NET ProgrammingC#
6 Comments1 Solution158 ViewsLast Modified:
Is it possible for the following task to be "inlined" and run on the current thread when the t.Wait(); is encountered?
Task t = Task.Run(() => MyMethod());
t.Wait();
If so, can you provide some example code that does this?

(I've tried setting ThreadPool.SetMaxThreads(8, 8); (This succeeds. My computer has 8 CPUs.) and then launching a dozen tasks via Task.Run() to try and fill up the ThreadPool so my Task t = Task.Run() gets queued but not run. However, I have not been able to get t.Wait(); to "inline to inline the task. So far it just always waits I assume for a free ThreadPool thread to become available.)
ASKER CERTIFIED SOLUTION
deleyd
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros