private async Task DoEventAsync(AsyncViewModel events, string eventName)
 {
     await Task.Run(() =>
     {
         DoEvent(events, eventName);
     });
 }
Beispiel #2
0
        public static async Task <T> WithBusyIndicator <T>(this Task <T> self, AsyncViewModel vm = null)
        {
            if (vm != null)
            {
                vm.IsBusy = true;
            }

            try
            {
                return(await self.ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                //TODO: Tratar erro
                Mvx.Trace(MvxTraceLevel.Error, ex.Message);
                return(default(T));
            }
            finally
            {
                if (vm != null)
                {
                    vm.IsBusy = false;
                }
            }
        }
        public async Task <ActionResult> TestMultiThreadedOrder()
        {
            var events = new AsyncViewModel();

            await DoEventAsync(events, "Event 1");
            await DoEventAsync(events, "Event 2");
            await DoEventAsync(events, "Event 3");

            return(View("TestMultiThreaded", events));
        }
        public async Task <IActionResult> TestMultiThreaded()
        {
            var events = new AsyncViewModel();

            var event1 = DoEventAsync(events, "Event 1");
            var event2 = DoEventAsync(events, "Event 2");
            var event3 = DoEventAsync(events, "Event 3");

            await Task.WhenAll(event1, event2, event3);

            return(View("TestMultiThreaded", events));
        }
 private void DoEvent(AsyncViewModel events, string eventName)
 {
     for (var i = 0; i < 10; i++)
     {
         Thread.Sleep(100);
         events.Bag.Add(new EventTagViewModel
         {
             Event = $"({HttpContext?.Request.GetDisplayUrl() }) {eventName} - {i}",
             Date  = DateTime.Now
         });
     }
 }
Beispiel #6
0
 private void DoEvent(AsyncViewModel events, string eventName)
 {
     for (var i = 0; i < 10; i++)
     {
         Thread.Sleep(100);
         events.Bag.Add(new EventTagViewModel
         {
             Event = $"({RootContext.Current?.Request.Url }) {eventName} - {i}",
             Date  = DateTime.Now
         });
     }
 }
Beispiel #7
0
        public async System.Threading.Tasks.Task ExternalCallEqualsInternalCall()
        {
            base.Setup();
            var got  = new WeatherData();
            var vm   = new AsyncViewModel(new AsyncService());
            var serv = new AsyncService();

            got = await serv.GetWeatherAsync("84627", "us", WeatherUnits.Metric);

            vm.ZipCode     = "84627";
            vm.CountryCode = "us";

            await vm.Recalculate();

            var expected = vm.Weather.WeatherDayInfo.Temperature;
            var actual   = got.WeatherDayInfo.Temperature;

            Assert.AreEqual(actual, expected);
        }
Beispiel #8
0
        public async System.Threading.Tasks.Task Test()
        {
            base.Setup();
            var got  = new WeatherData();
            var vm   = new AsyncViewModel(new AsyncService());
            var serv = new AsyncService();


            try
            {
                //Failed Call
                got = await serv.GetWeatherAsync("AFSDFASDF", "us", WeatherUnits.Metric);
            }
            catch (Exception e)
            {
                if (e != null)
                {
                    Assert.Pass();
                }
            }

            Assert.Fail();
        }
        private async Task DoEventNotAsync(AsyncViewModel events, string eventName, int delay)
        {
            await Task.Delay(delay);

            DoEvent(events, eventName);
        }