He copiado este ejemplo de hereTratando de aprender acerca de las nuevas funciones asíncronas en C#
he visto muchos ejemplos similares. La mayoría de ellos dicen que están usando Async CTP. Estoy usando Visual Studio 11 en Windows 8, así que eso no se aplica. Como se muestra, el error dice que TaskEx no existe. Supongo que me falta una referencia, pero no sé cuál.
Esta página es http://users.zoominternet.net/~charleswatson/pic.png.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static Random rnd = new Random();
static void Main(string[] args)
{
//Do some other heavy duty background task in this thread
StartHotel();
Console.WriteLine("StartHotel called..");
Console.ReadLine();
}
static void StartHotel()
{
Console.WriteLine("Starting Hotel..");
for (int i = 0; i < 10; i++)
{
string name = "Chef" + i;
CookDish(name, "Dish" + i);
Console.WriteLine("Asked {0} to start cooking at {1}", name, DateTime.Now.ToString());
}
}
static async void CookDish(string chefName, string dish)
{
//Induce a random delay
int delay = rnd.Next(1000, 4000);
//Cook is cooking - Task
await TaskEx.Delay(delay);
//Write the result - StuffAfterAwait
Console.WriteLine("Chef {0} Finished at {1}", chefName, DateTime.Now.ToString());
}
}
}
Simplemente haga clic con el botón derecho-> abrir. La imagen se reduce a escala mediante css. – Femaref
@Femaref: Ah, perfecto. Gracias –
Simplemente haga clic en el enlace de ejemplo –