Bug 42547 - async VS 2015 debug callstack problems
Summary: async VS 2015 debug callstack problems
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-07-14 02:55 UTC by philip
Modified: 2017-06-28 15:25 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description philip 2016-07-14 02:55:01 UTC
In our application we invoke to the UI thread in various places.
In order to make the debugging/profiling experience better we would like to see the debug call stack past the Device.BeginInvokeOnMainThread() call.  For this we want to use the following kludge when profiling and debugging:

        static public async Task InvokeOnMainThreadWithCallstackAsync(Func<Task> action)
        {
            if (SynchronizationContext.Current == null)
            {
                Task t = null;
                var tcs = new TaskCompletionSource<object>();
                Device.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        Func<Task> x = async () =>
                        {
                            await tcs.Task;
                            await action.Invoke();
                        };
                        t = x.Invoke();
                    }
                    catch
                    {
                        Debugger.Break();
                    }
                });
                while (t == null)
                    ; //await Task.Delay(1);
                tcs.SetResult(null);
                CrossPlatform.Assert(t.Status == TaskStatus.WaitingForActivation);
                await t;
            }
            else
                await action();
        }

However, when breaking the VS debugger inside the action, the callstack does not go up to TestInvokeOnMainThreadAsync() as it should. Since we are awaiting t, I would expect the callstack to extend back to the caller of TestInvokeOnMainThreadAsync().
Comment 1 Jonathan Pryor 2016-07-28 19:36:30 UTC
> I would expect the callstack to extend back to the caller
> of TestInvokeOnMainThreadAsync().

What callback do you see instead?

Would it be possible for you to create a small test case to demonstrate the behavior?
Comment 2 John Miller [MSFT] 2017-06-28 15:25:59 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!