Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve queue error handling #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Source/Plugin.BLE.Android/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,27 @@ public void CloseGatt()
GattServer?.Close();
GattServer = null;

while (_gattList.Any())
while (_gattList.Count() > 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer .Any here but both work the same

{
var g = _gattList.Dequeue();
if (g != null)
try
{
try
var g = _gattList.Dequeue();
if (g != null)
{
g.Disconnect();
g.Close();
}
catch (Exception e)
{
Trace.Message(e.Message);
throw;
}
}
catch (InvalidOperationException invalidOpException)
{
Trace.Message($"Gatt queue is empty while trying to close gatt instances: {invalidOpException.Message}. Queue size: {_gattList.Count()}");
break;
}
catch (Exception e)
{
Trace.Message($"Error while closing gatt instances: {e.Message}");
}

}

// ClossGatt might will get called on signal loss without Disconnect being called we have to make sure we clear the services
Expand Down