lunes, 24 de junio de 2019

Hilo ASPX C#

[WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string Hilo() {

            List<string> d = new List<string>();
       
            d.Add(ShowTodaysInfo(100).Result);
            return JsonConvert.SerializeObject(d, Formatting.Indented);
        }
     
        /**********************************************************/
        private static async Task<string> ShowTodaysInfo(int Dato)
        {
            string ret = $"Today is {DateTime.Today:D}\n" +
                         "Today's hours of leisure: " +
                         $"{await GetLeisureHours(Dato)}";
            return ret;
        }
        static async Task<int> GetLeisureHours(int dato)
        {

            // Task.FromResult es un marcador de posición para el trabajo real que devuelve una cadena.
            var today = await Task.FromResult<string>(DateTime.Now.DayOfWeek.ToString());


            // El método entonces puede procesar el resultado de alguna manera.
            int leisureHours;
            if (today.First() == 'M')
                leisureHours = 16;
            else
                leisureHours = 5;


            leisureHours = dato;
            for (int i = 0; i < 500; i++) {
                leisureHours = leisureHours + 1;
            }
            return leisureHours;
        }

No hay comentarios:

Publicar un comentario