3

I have an issue with Visual Studio 2017. When I would to call a method with "await" and press Ctrl + . to add "async" to method, VS2017 will force to add "async" at method name, this is useful sometimes but make it not right in some override method like "OnNavigatedTo" because "OnNavigatedToAsync" method not exist. In VS2015, this problem not happen

enter image description here

I wondering if have any option to fix this issue?

HelloWindowsPhone
  • 680
  • 10
  • 19
  • it is a bug in your code, nothing to do with VS2017. You can only use `await` in a method that you declared `async`. So use the handy-dandy code fixer, "Make method async (stay void)" trivially fixes your bug. – Hans Passant Mar 09 '17 at 12:54
  • 2
    No, you don't understand the question. In VS 2015, when call "await" you can simply (Ctrl + .) to add "async" to method prefix without change method name. Now in VS 2017, it additional add add "...Async" to method name. It make "override OnNavigatedTo" become "override OnNavigatedToAsync", which not exist. – HelloWindowsPhone Mar 09 '17 at 13:34
  • 1
    You are absolutely correct, it renames the method. I agree this can be undesirable depending on the circumstance. Actually it's funny they did this because right in MS's own proposal at https://github.com/dotnet/csharplang/blob/master/proposals/async-main.md they state "While the async suffix is recommended for Task-returning methods, that's primarily about library functionality" and not every async method is for use in a library... I have yet to find a way around this. – dmeglio Mar 09 '17 at 14:34
  • 1
    After spending some time, I do not think there is any way to disable this. I would recommend filing an issue at https://github.com/dotnet/roslyn since there are definitely times when you do NOT want to add an Async suffix. – dmeglio Mar 09 '17 at 16:04
  • I reported it in Visual Studio feedback. Hope they can fix it soon – HelloWindowsPhone Mar 10 '17 at 02:11

1 Answers1

-1

In Visual Studio 2017 Community or previous version also, if you want to call await inside the method body, then the method you have to define as an async type.

Just add like this,

Protected override async void YourFunctionName()
{
     await ..code..
}