Exemple #1
0
        private static void testBrokenPromises()
        {
            var leakTaskCompletionSource = new LeakTaskCompletionSource();
            var task = leakTaskCompletionSource.Leak();

            DebugTaskCompletionSourceServices.DetectBrokenTaskCompletionSources();
        }
Exemple #2
0
        public static async Task runBackgroundProcessor()
        {
            const int DELAY_MS  = 2000;
            var       processor = new BackgroundProcessor();
            var       task      = processor.RunBackgroundOperation(() => Console.WriteLine("Moje operace 1"), "Operace 1");
            var       task2     = processor.RunBackgroundOperation(() =>
            {
                Console.WriteLine("Moje operace 2");
                throw new InvalidOperationException();
            }, "Operace s výjimkou");

            //Race condition!
            await Task.Delay(DELAY_MS);

            //Race condition!
            DebugTaskCompletionSourceServices.DetectBrokenTaskCompletionSources();
            await task;

            Console.WriteLine("Wait 1 done");

            try
            {
                await task2;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("Wait 2 done");
            }
        }