public IList <Juice> GetJuiceList() { try { using (FileStream file = new FileStream(@"Juice.txt", FileMode.Open, FileAccess.Read)) { juiceList.Clear(); StreamReader readFile = new StreamReader(file); while (!readFile.EndOfStream) { var line = readFile.ReadLine(); var lines = line.Split(','); var juice = new Juice(); juice.Name = lines[0]; juice.IsCustom = Boolean.Parse(lines[1]); juice.Approved = Boolean.Parse(lines[2]); juice.JuiceDateTime = DateTime.Parse(lines[3]); juice.UserName = lines[4]; } readFile.Close(); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } return(juiceList); }
private static async Task Main(string[] args) { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Egg eggs = await FryEggsAsync(2); Console.WriteLine("eggs are ready"); Bacon bacon = await FryBaconAsync(3); Console.WriteLine("bacon is ready"); Toast toast = await ToastBreadAsync(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); }
public virtual void ClassMain() { WriteLine("-*-*-*-*-* coffee is prepearing *-*-*-*-*-"); Coffee cup = PourCoffee(); WriteLine("-*-*-*-*-* coffee is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* egg is prepearing *-*-*-*-*-"); Egg eggs = FryEggs(2); WriteLine("-*-*-*-*-* egg is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* bacon is prepearing *-*-*-*-*-"); Bacon bacon = FryBacon(3); WriteLine("-*-*-*-*-* bacon is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* toast is prepearing *-*-*-*-*-"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); WriteLine("-*-*-*-*-* toast is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* Juice is prepearing *-*-*-*-*-"); Juice oj = PourOJ(); // oj = orange juice WriteLine("-*-*-*-*-* Juice is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* Breakfast is ready! *-*-*-*-*-"); }
// Začnimo z običajnim primerom - primer slabe prakse public static void BreakfastBadExample() { Stopwatch sw = Stopwatch.StartNew(); Console.WriteLine("Pripravimo si dober zajtrk brez asinhronih pristopov!"); Coffee cup = PourCoffee(); Console.WriteLine("\n----> coffee is ready"); Egg eggs = FryEggs(2); Console.WriteLine("\n----> eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("\n----> bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("\n----> toast is ready"); Juice oj = PourOJ(); Console.WriteLine("\n----> oj is ready"); Console.WriteLine("\n----> ----> Breakfast is ready!"); Console.WriteLine($"Zajtrk smo si pripravili v {sw.Elapsed.TotalSeconds} sekundah!"); }
public async Task PrepareBreakfast2() { Coffee coffee = PourCoffee(); Task <Egg> eggTask = FryEggAsync(2); Task <Bacon> baconTask = FryBaconAsync(3); Task <Toast> toastTask = ToastBreadAsync(2); // Before applying butter and jam, we have to take it out of the toaster.... var toast = await toastTask; ApplyButter(toast); ApplyJam(toast); Juice oj = PourOJ(); // Before breakfast is ready, all tasks need to be finished. // All tasks are running asynchronously, until they are all completed. await Task.WhenAll(eggTask, baconTask, toastTask); Console.WriteLine("Breakfast is ready"); Console.ReadLine(); }
public async Task PrepareBreakfast3() { Coffee coffee = PourCoffee(); Task <Egg> eggTask = FryEggAsync(2); Task <Bacon> baconTask = FryBaconAsync(3); Task <Toast> toastTask = ToastBreadAsync(2); toastTask = ToastWithButterAndJam(toastTask); async Task <Toast> ToastWithButterAndJam(Task <Toast> breadToasting) { var toast = await breadToasting; ApplyButter(toast); ApplyJam(toast); return(toast); } Juice oj = PourOJ(); // Before breakfast is ready, all tasks need to be finished. // All tasks are running asynchronously, until they are all completed. await Task.WhenAll(eggTask, baconTask, toastTask); Console.WriteLine("Breakfast is ready"); Console.ReadLine(); }
static async Task Main(string[] args) { Console.WriteLine("1. Start!"); Coffee cup = PourCoffee(); Console.WriteLine("3. coffee is ready"); Task <Egg> eggsTask = FryEggs(2); Task <Bacon> baconTask = FryBacon(3); var eggsAndBaconTask = Task.WhenAll(eggsTask, baconTask); await eggsAndBaconTask; Console.WriteLine("8. eggs are ready"); Console.WriteLine("14. bacon is ready"); Toast toast = await ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("20. toast is ready"); Juice oj = PourOJ(); Console.WriteLine("22. oj is ready"); Console.WriteLine("23. Breakfast is ready!"); Console.WriteLine("24. End!"); Console.ReadLine(); }
private static void Main(string[] args) { Stopwatch watch = Stopwatch.StartNew(); Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Task.Run(() => { Egg eggs = FryEggs(2); }); Console.WriteLine("eggs are ready"); Task.Run(() => { Bacon bacon = FryBacon(3); }); Console.WriteLine("bacon is ready"); Toast toast = new Toast(); Task.Run(() => { toast = ToastBread(2); }); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); watch.Stop(); double seconds = watch.Elapsed.TotalSeconds; Console.WriteLine(seconds); }
static async Task CookImprovedBreakfast() { DateTime time = DateTime.Now; Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Task <Egg> eggsTask = FryEggsAsync(2); Task <Bacon> baconTask = FryBaconAsync(3); Task <Toast> toastTask = ToastBreadAsync(2); Toast toast = await toastTask; ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Egg eggs = await eggsTask; Console.WriteLine("eggs are ready"); Bacon bacon = await baconTask; Console.WriteLine("bacon is ready"); Console.WriteLine("Breakfast is ready!"); Console.WriteLine($"It took {DateTime.Now - time} seconds"); }
static void Main(string[] args) { DateTime startTime = DateTime.Now; Console.WriteLine("***** 아침식사 준비 시작 *****"); Task <Egg> eggsTask = FryEggs(2); var baconTask = FryBaconAsync(3); var toastTask = ToastBreadAsync(2); toastTask.Wait(); ApplyButter(toastTask.Result); ApplyJam(toastTask.Result); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); eggsTask.Wait(); Console.WriteLine("eggs are ready"); baconTask.Wait(); Console.WriteLine("bacon is ready"); Console.WriteLine("Breakfast is ready!"); DateTime endTime = DateTime.Now; TimeSpan elapsed = endTime - startTime; Console.WriteLine($"준비 시간: {elapsed}"); }
public List <Juice> GetallJuiceFlavours() { List <Juice> juiceslst = new List <Juice>(); { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=IN-5CG0255ZN3\SQLEXPRESS;Initial Catalog=JuiceShop_DB;Integrated Security=True"; SqlCommand cmd = new SqlCommand("select * from juice", con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Juice j = new Juice { juiceid = (int)sdr[0], juice_flavour = sdr[1].ToString(), price = (int)sdr[2] }; juiceslst.Add(j); } sdr.Close(); con.Close(); return(juiceslst); } }
private static void MakeBreakfast() { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Egg eggs = FryEggs(2); Console.WriteLine("eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); }
public void MakeBreakFast() { var st = new Stopwatch(); st.Start(); Coffee cup = PourCoffee(1000); Console.WriteLine("coffee is ready"); Egg eggs = FryEggs(2000); Console.WriteLine("eggs are ready"); Bacon bacon = FryBacon(3000); Console.WriteLine("bacon is ready"); Toast toast = ToastBread(2000); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(3); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready! Elapsed: " + st.ElapsedMilliseconds + " ms"); }
static async Task Main(string[] args) { Console.WriteLine(DateTime.Now); Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Task <Egg> eggTask = FryEggs(2); Task <Bacon> baconTask = FryBacon(3); Task <Toast> toastTask = MakeToastWithButterAndJamAsync(2); Toast toast = await toastTask; //ApplyButter(toast); //ApplyJam(toast); //Console.WriteLine("toast is ready"); Egg egg = await eggTask; //FryEggs(2); Console.WriteLine("eggs are ready"); Bacon bacon = await baconTask; //FryBacon(3); Console.WriteLine("bacon is ready"); Console.WriteLine("Breakfast is ready!"); Console.WriteLine(DateTime.Now); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("1. Start!"); Coffee cup = PourCoffee(); Console.WriteLine("3. coffee is ready"); Egg eggs = FryEggs(2); Console.WriteLine("8. eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("14. bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("20. toast is ready"); Juice oj = PourOJ(); Console.WriteLine("22. oj is ready"); Console.WriteLine("23. Breakfast is ready!"); Console.WriteLine("24. End!"); }
static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Egg eggs = FryEggs(2); Console.WriteLine("eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); stopwatch.Stop(); Console.WriteLine($"Total time : {stopwatch.Elapsed}"); }
private void button7_Click(object sender, EventArgs e) { Task task = new Task(); task.EscreveLinha += EscreveLinha; EscreveLinha("Inicio:" + DateTime.Now.ToString()); Coffee cup = task.PourCoffee(); EscreveLinha("Café Preto está pronto"); Egg eggs = task.FryEggs(2); EscreveLinha("Ovos estão prontos"); Bacon bacon = task.FryBacon(3); EscreveLinha("Bacon estão prontos"); Toast toast = task.ToastBread(2); task.ApplyButter(toast); task.ApplyJam(toast); EscreveLinha("Torradas estão prontos"); Juice oj = task.PourOJ(); EscreveLinha("Suco de Laranja estão prontos"); EscreveLinha("Cafe da manha concluido!"); EscreveLinha("Fim:" + DateTime.Now.ToString()); }
private static async Task MakeBreakfastAsync() { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); var eggsTask = FryEggsAsync(2); var baconTask = FryBaconAsync(3); var toastTask = MakeToastWithButterAndJamAsync(2); var eggs = await eggsTask; Console.WriteLine("eggs are ready"); var bacon = await baconTask; Console.WriteLine("bacon is ready"); var toast = await toastTask; Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); }
public string AddDrink(string type, string name, int servingSize, string brand) { IDrink drink = null; switch (type.ToLower()) { case "fuzzydrink": drink = new FuzzyDrink(name, servingSize, brand); break; case "juice": drink = new Juice(name, servingSize, brand); break; case "water": drink = new Water(name, servingSize, brand); break; case "alcohol": drink = new Alcohol(name, servingSize, brand); break; default: throw new ArgumentException($"Invalid drink type {type}!"); } this.drinks.Add(drink); return($"Added {drink.Name} ({drink.Brand}) to the drink pool"); }
public string AddDrink(string type, string name, int servingSize, string brand) { IDrink drink = null; if (type == "Alcohol") { drink = new Alcohol(name, servingSize, brand); } else if (type == "FuzzyDrink") { drink = new FuzzyDrink(name, servingSize, brand); } else if (type == "Juice") { drink = new Juice(name, servingSize, brand); } else if (type == "Water") { drink = new Water(name, servingSize, brand); } if (drink != null) { this.drinks.Add(drink); } return($"Added {drink.Name} ({drink.Brand}) to the drink pool"); }
public async Task ClassMain() { WriteLine("-*-*-*-*-* coffee is prepearing *-*-*-*-*-"); Coffee cup = PourCoffee(); WriteLine("-*-*-*-*-* coffee is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* eggs is prepearing *-*-*-*-*-"); Egg eggs = await FryEggsAsync(2); WriteLine("-*-*-*-*-* eggs is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* bacon is prepearing *-*-*-*-*-"); Bacon bacon = await FryBaconAsync(3); WriteLine("-*-*-*-*-* bacon is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* toast is prepearing *-*-*-*-*-"); Toast toast = await ToastBreadAsync(2); ApplyButter(toast); ApplyJam(toast); WriteLine("-*-*-*-*-* toast is ready *-*-*-*-*-"); WriteLine("-*-*-*-*-* oj is prepearing *-*-*-*-*-"); Juice oj = PourOJ(); // oj = orange juice WriteLine("-*-*-*-*-* oj is ready *-*-*-*-*-"); WriteLine("Breakfast is ready!"); }
public IDrink CreateDrink(string type, string name, int servingSize, string brand) { IDrink drink; if (type == "FuzzyDrink") { drink = new FuzzyDrink(name, servingSize, brand); } else if (type == "Juice") { drink = new Juice(name, servingSize, brand); } else if (type == "Water") { drink = new Water(name, servingSize, brand); } else if (type == "Alcohol") { drink = new Alcohol(name, servingSize, brand); } else { throw new InvalidOperationException("Wrong type of drink!"); } return(drink); }
/* * This code doesn't block while the eggs or the bacon are cooking. * This code won't start any other tasks though. You'd still put the toast in the toaster and stare at it until it pops. * But at least, you'd respond to anyone that wanted your attention. In a restaurant where multiple orders are placed, * the cook could start another breakfast while the first is cooking. * Now, the thread working on the breakfast isn't blocked while awaiting any started task that hasn't yet finished. * For some applications, this change is all that's needed. * A GUI application still responds to the user with just this change. * However, for this scenario, you want more. You don't want each of the component tasks to be executed sequentially. * It's better to start each of the component tasks before awaiting the previous task's completion. */ public async Task PrepareBreakfastAsync() { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Console.WriteLine(); Egg eggs = await FryEggs(2); Console.WriteLine("eggs are ready"); Console.WriteLine(); Bacon bacon = await FryBacon(3); Console.WriteLine("bacon is ready"); Console.WriteLine(); Toast toast = await ToastBread(4); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Console.WriteLine(); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine(); Console.WriteLine("Breakfast is ready!"); }
static void CookBreakFastSyncronized() { DateTime time = DateTime.Now; Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Egg eggs = FryEggs(2); Console.WriteLine("eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); Console.WriteLine($"It took {DateTime.Now - time} seconds"); }
public async Task PrepareBreakfastAsync() { Console.WriteLine("Let's prepare Breakfast"); Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); var eggsTask = FryEggsAsync(2); //Egg eggs = await eggsTask; //Console.WriteLine("eggs are ready"); // Toast toast = ToastBread(2); var toastTask = ToastBreadAsync(2); Toast toast = await toastTask; Console.WriteLine("Toasting is completed"); ApplyButter(toast); Juice juice = PourOj(); Console.WriteLine("juice is ready"); await Task.WhenAll(eggsTask, toastTask); Console.WriteLine("eggs are ready"); Console.WriteLine("Breakfast is ready!"); Console.WriteLine("Breakfast is ready"); }
static void Main(string[] args) { Console.WriteLine("***** 아침 식사 준비 시작 *****\n"); DateTime startTime = DateTime.Now; Egg eggs = FryEggs(2); Console.WriteLine("eggs are ready"); Bacon bacon = FryBacon(3); Console.WriteLine("bacon is ready"); Toast toast = ToastBread(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); DateTime endTime = DateTime.Now; TimeSpan elapsed = endTime - startTime; // 두 날짜 사이의 시간 간격 저장 Console.WriteLine($"실행 시간: {elapsed}"); }
static async Task Main(string[] args) { Coffee cup = await PourCoffee(); await Console.Out.WriteLineAsync("Coffee is ready"); Egg eggs = await FryEggs(2); await Console.Out.WriteLineAsync("Eggs are ready"); Bacon bacon = await FryBacon(3); await Console.Out.WriteLineAsync("Bacon is ready"); Toast toast = await ToastBread(2); await ApplyButter(toast); await ApplyJam(toast); await Console.Out.WriteLineAsync("toast is ready"); Juice orange = await PourOJ(); await Console.Out.WriteLineAsync("Orange juice is ready"); await Console.Out.WriteLineAsync("Breakfast is ready!"); }
public async void MakeBreakFast() { var st = new Stopwatch(); st.Start(); var cup = PourCoffee(1000); Console.WriteLine($"coffee is ready({Thread.CurrentThread.ManagedThreadId})"); var eggsTask = FryEggsAsync(2000); var baconTask = FryBaconAsync(3000); var toastTask = MakeToastWithButterAndJamAsync(2000); var toast = await toastTask; Console.WriteLine($"toast is ready({Thread.CurrentThread.ManagedThreadId})"); Juice oj = PourOJ(3); Console.WriteLine($"oj is ready({Thread.CurrentThread.ManagedThreadId})"); var eggs = await eggsTask; Console.WriteLine($"eggs are ready({Thread.CurrentThread.ManagedThreadId})"); var bacon = await baconTask; Console.WriteLine($"bacon is ready({Thread.CurrentThread.ManagedThreadId})"); Console.WriteLine($"Breakfast is ready! Elapsed: {st.ElapsedMilliseconds } ms({Thread.CurrentThread.ManagedThreadId})"); }
public static IDrink CreateDrink(string type, string name, int servingSize, string brand) { IDrink drink; switch (type) { case "Alcohol": drink = new Alcohol(name, servingSize, brand); break; case "Juice": drink = new Juice(name, servingSize, brand); break; case "FuzzyDrink": drink = new FuzzyDrink(name, servingSize, brand); break; case "Water": drink = new Water(name, servingSize, brand); break; default: drink = null; break; } return(drink); }
public async Task MakeBreakfast() { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Task <Egg> eggsTask = FryEggsAsync(2); Task <Bacon> baconTask = FryBaconAsync(3); Task <Toast> toastTask = ToastBreadAsync(2); Toast toast = await ToastBreadAsync(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); Egg eggs = await eggsTask; Console.WriteLine("eggs are ready"); Bacon bacon = await baconTask; Console.WriteLine("bacon is ready"); }
#pragma warning restore 0414 #endregion void Awake() { Instance = this; mCallbacks = new List<System.Action>(); mComponents = new List<Object>(); }
void Start() { _otherScript = GetComponent<Juice>(); }