SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Windows Phone Application Development Tutorials, Articles and Resources for Mobile App Programmers

The 'await' operator can only be used within an async method.

While I was coding during a task in Windows Phone 8 app development, I got the following error message from Microsoft Visual Studio 2012 IDE.

The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

I soon realized that I was to in a hurry to place the async task launcher code in the tap event code in code behind of the Windows Phone page. When I added the async method identifier the error is resolved by itself.

For example, in the following button on tap event code, instead of running the LaunchUriAsync() method I placed the same code in a new method marked with async keyword.

private void btnWifi_Tap(object sender, System.Windows.Input.GestureEventArgs e)

private async void launchUriScheme()
 Uri uri = new Uri("ms-settings-wifi:");
 await Windows.System.Launcher.LaunchUriAsync(uri);

By the way, Windows Phone app developers can use the above sample C# code to open the default Wi-Fi settings app from their Windows Phone 8 program.

The above change helped me to resolve the "The 'await' operator can only be used within an async method." error message.

Windows 10 Games

Microsoft Games on Windows 8 and Windows 10

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.