?
Solved

Threading Convert C# 4.0 / 3.5

Posted on 2010-11-18
1
Medium Priority
?
575 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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