Using light bulb action to refactor asynchronous method to synchronous – Visual Studio 2015

Using light bulb action to refactor asynchronous method to synchronous – Visual Studio 2015

In Visual Studio 2015, using the light bulb action, we can simplify the refactoring a method from Asynchronous to Synchronous when it does not use any ‘await’ .  In case you don’t have an await call inside the method definition, the IDE refactoring light bulb will show an indication and will give you hints to refactor .  You can apply this refactoring to entire project or solution. IDE

Consider you have following method where you indented to make an async call to service, where as your service call is a synchronous ,

Refactoring

The yellow light build indicates that the method does not have any ‘await’ operator and it is suggesting to refactor it to a synchronous  method.

 

Refactoring Async To Sync

You can apply this for this file, project or even entire solution, so that the refactoring can be done throughout.

Related Tip : Add Using command for misspelled types using”fuzzy” matching – Visual Studio 2015

Alternatively, if you have an ‘await’ operator, but you missed the async, if you can take help of light bulb operator to change.

 

image

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

5 Comments to “Using light bulb action to refactor asynchronous method to synchronous – Visual Studio 2015”

  1. Mladen Mihajlovic

    Hi Abhijit

    I love your .net tips but could I make a small suggestion about your blog. Whenever you show source code images, the fonts and colours make your blog look messy and therefore it’s a bit hard to follow. Could you maybe try changing the background of the images to something darker so that they stick out a bit more and therefore the eye would not try and follow the test as if it was part of the blog post. (Also choosing the dark theme in vs when taking the images would allow for the same effect)

  2. Abhijit Jana Author

    Could you please share some screenshots.. on what you are looking in .. I really appreciate your feedback, and will change accordingly..
    Thank you.

Comments are closed.