?
Solved

Threading Convert C# 4.0 / 3.5

Posted on 2010-11-18
1
Medium Priority
?
573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Richard Lee earned 2000 total points
ID: 34163953
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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