Solved

Threading Convert C# 4.0 / 3.5

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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