Skip to content

Commit

Permalink
Add ConfigAwait to async calls (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Oct 23, 2017
1 parent 19e5046 commit 9e8b684
Show file tree
Hide file tree
Showing 23 changed files with 276 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private void OnAppDeactivated(object sender, EventArgs args)
/// An exception may be thrown if the device could not be opened for extraordinary reasons.</returns>
public async Task<bool> OpenDeviceAsync(DeviceInformation deviceInfo, string deviceSelector)
{
await Task.Delay(250);

#pragma warning disable ConfigureAwaitChecker // CAC001
device = await SerialDevice.FromIdAsync(deviceInfo.Id);
#pragma warning restore ConfigureAwaitChecker // CAC001

bool successfullyOpenedDevice = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public partial class EventHandlerForUsbDevice
/// </summary>
private void RegisterForDeviceAccessStatusChange()
{
deviceAccessInformation = DeviceAccessInformation.CreateFromId(deviceInformation.Id);
//deviceAccessInformation = DeviceAccessInformation.CreateFromId(deviceInformation.Id);

deviceAccessEventHandler = new TypedEventHandler<DeviceAccessInformation, DeviceAccessChangedEventArgs>(OnDeviceAccessChanged);
deviceAccessInformation.AccessChanged += deviceAccessEventHandler;
//deviceAccessEventHandler = new TypedEventHandler<DeviceAccessInformation, DeviceAccessChangedEventArgs>(OnDeviceAccessChanged);
//deviceAccessInformation.AccessChanged += deviceAccessEventHandler;
}

/// <summary>
Expand All @@ -48,7 +48,9 @@ private void RegisterForDeviceAccessStatusChange()
/// An exception may be thrown if the device could not be opened for extraordinary reasons.</returns>
public async Task<bool> OpenDeviceAsync(DeviceInformation deviceInfo, String deviceSelector)
{
#pragma warning disable ConfigureAwaitChecker // CAC001
device = await Windows.Devices.Usb.UsbDevice.FromIdAsync(deviceInfo.Id);
#pragma warning restore ConfigureAwaitChecker // CAC001

bool successfullyOpenedDevice = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ For UWP look for the respective Nuget package.</PackageReleaseNotes>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\ConfigureAwaitChecker.Analyzer.1.0.0\analyzers\dotnet\cs\ConfigureAwaitChecker.dll" />
<Analyzer Include="..\packages\UwpDesktop.10.0.14393.3\analyzers\dotnet\UwpDesktopAnalyzer.dll" />
</ItemGroup>
<Import Project="..\nanoFramework.Tools.DebugLibrary.Shared\nanoFramework.Tools.DebugLibrary.Net.projitems" Label="Shared" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ConfigureAwaitChecker.Analyzer" version="1.0.0" targetFramework="net46" developmentDependency="true" />
<package id="NuGet.Build.Packaging" version="0.2.0" targetFramework="net46" developmentDependency="true" />
<package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net46" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net46" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class DebuggerExtensions
/// <returns></returns>
public static async Task<bool> IsDeviceInInitializeStateAsync(this Engine debugEngine)
{
var result = await debugEngine.SetExecutionModeAsync(0, 0);
var result = await debugEngine.SetExecutionModeAsync(0, 0).ConfigureAwait(false);

if (result.success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public async Task<bool> GetDeviceInfo()
if (!Dbg.IsConnectedTonanoCLR) return false;

// get app domains from device
await GetAppDomainsAsync(cancelTSource.Token);
await GetAppDomainsAsync(cancelTSource.Token).ConfigureAwait(false);

// get assemblies from device
await GetAssembliesAsync(cancelTSource.Token);
await GetAssembliesAsync(cancelTSource.Token).ConfigureAwait(false);

Valid = true;

Expand All @@ -50,14 +50,14 @@ private async Task GetAppDomainsAsync(CancellationToken cancellationToken)
{
if (Dbg.Capabilities.AppDomains)
{
Commands.Debugging_TypeSys_AppDomains.Reply domainsReply = await Dbg.GetAppDomainsAsync();
Commands.Debugging_TypeSys_AppDomains.Reply domainsReply = await Dbg.GetAppDomainsAsync().ConfigureAwait(false);
// TODO add cancellation token code

if (domainsReply != null)
{
foreach (uint id in domainsReply.Data)
{
Commands.Debugging_Resolve_AppDomain.Reply reply = await Dbg.ResolveAppDomainAsync(id);
Commands.Debugging_Resolve_AppDomain.Reply reply = await Dbg.ResolveAppDomainAsync(id).ConfigureAwait(false);
// TODO add cancellation token code
if (reply != null)
{
Expand All @@ -70,7 +70,7 @@ private async Task GetAppDomainsAsync(CancellationToken cancellationToken)

private async Task GetAssembliesAsync(CancellationToken cancellationToken)
{
List<Commands.DebuggingResolveAssembly> reply = await Dbg.ResolveAllAssembliesAsync(cancellationToken);
List<Commands.DebuggingResolveAssembly> reply = await Dbg.ResolveAllAssembliesAsync(cancellationToken).ConfigureAwait(false);

if (reply != null)
foreach (Commands.DebuggingResolveAssembly resolvedAssm in reply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public async Task<bool> ConnectAsync()
{
if (Device is NanoUsbDevice)
{
return await Parent.ConnectDeviceAsync(this as NanoDeviceBase);
return await Parent.ConnectDeviceAsync(this as NanoDeviceBase).ConfigureAwait(false);
}
else if (Device is NanoSerialDevice)
{
return await Parent.ConnectDeviceAsync(this as NanoDeviceBase);
return await Parent.ConnectDeviceAsync(this as NanoDeviceBase).ConfigureAwait(false);
}

return false;
Expand Down
Loading

0 comments on commit 9e8b684

Please sign in to comment.