Solved

Threading Convert C# 4.0 / 3.5

Posted on 2010-11-18
1
571 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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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