Пример #1
0
        /*
         *  Trace:
         *      On UI thread: BEGINNING of EventHandler
         *      On UI thread: Beginning of DangerousMethodAsync
         */
        private void BLOCKING_UI_CALL_WITH_DEADLOCK(object sender, EventArgs e)
        {
            Logger.Write("BEGINNING of EventHandler"); // on UI thread

            Task.WaitAll(_service.DangerousMethodAsync(), _task2, _task3);

            Logger.Write("END of EventHandler"); // on UI thread
        }
Пример #2
0
        /*
         * Trace:
         *      On UI thread: Beginning of EventHandlerMethod
         *      On UI thread: Beginning of DangerousMethodAsync
         *
         *    ---------DEADLOCK---------
         */
        private void BLOCKING_OF_UI_THREAD_WITH_DEADLOCK_DUE_TO_ConfigureAwaitTrue_IN_THE_LIBRARY_METHOD(object sender, EventArgs e)
        {
            Logger.Write("Beginning of EventHandlerMethod");   // on UI thread

            _service
            .DangerousMethodAsync()                    // on UI and on ThreadPool threads
            .Wait();                                   // BLOCK UI thread till the end of execution of library method

            Logger.Write("End of EventHandlerMethod"); // on UI thread
        }
Пример #3
0
        /*
         *   Trace:
         *      On UI thread: BEGINNING of EventHandler
         *      On UI thread: Beginning of GetText
         *
         *    ---------DEADLOCK---------
         */
        private void BLOCKING_UI_CALL_WITH_DEADLOCK(object sender, EventArgs e)
        {
            Logger.Write("BEGINNING of EventHandler"); // on UI thread

            var result = _service
                         .DangerousMethodAsync("https://www.google.com") // on UI and ThreadPool threads
                         .Result;                                        // BLOCK UI thread till the end of getting result from library method

            label1.Text = result;                                        // on UI thread

            Logger.Write("END of EventHandler");
        }