Solved

Threading Convert C# 4.0 / 3.5

Posted on 2010-11-18
1
560 Views
Last Modified: 2012-05-10
I'm REALLY new at do some good with threading (does not mean i'm not unfamiliar)
I would like to hear your opinion on how this .NET 4 would be in .NET 3.5 (perhaps also 2.0)

static void Main()
{
  Task<string> task = Task.Factory.StartNew<string> (() => DownloadString ("http://www.yahoo.com"));
  //xx something else
  string result = task.Result;
}
 
static string DownloadString (string uri)
{
   using (var wc = new System.Net.WebClient())
    return wc.DownloadString (uri);
}
0
Comment
Question by:dingir
1 Comment
 
LVL 18

Accepted Solution

by:
Richard Lee earned 500 total points
Comment Utility
These examples would do the same thing:

// Example 1
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (s,e) => DownloadString("http://www.yahoo.com");
bw.RunWorkerAsync();

// Example 2
ThreadPool.QueueUserWorkItem((state) =>  DownloadString("http://www.yahoo.com"));

// Example 3
Thread thread = new Thread(() => DownloadString("http://www.yahoo.com"));
thread.Start();

DaTribe
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Parameter transfer to cristal report 3 50
Get String split 5 31
Handle null when using linq in this line 1 20
XML & .net 5 16
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now