Skip to content

Commit

Permalink
Merge pull request #149 from t3knomanzer/hotfix-1.1.3
Browse files Browse the repository at this point in the history
Hotfix 1.1.3
  • Loading branch information
t3knomanzer authored Aug 27, 2020
2 parents 83774cb + d00dc95 commit a81f70c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 11 additions & 6 deletions Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ public void Start()
/// </summary>
public void Stop()
{
foreach (var session in _devices.Values)
session.Dispose();
foreach (AudioDevice device in _devices.Values)
{
device.SessionCreated -= OnSessionCreated;
device.SessionEnded -= OnSessionRemoved;
device.VolumeChanged -= OnSessionVolumeChanged;
device.Dispose();
}

_devices.Clear();
}
Expand Down Expand Up @@ -110,11 +115,11 @@ private void Initialize(object stateInfo)
using (var enumerator = new MMDeviceEnumerator())
{
var device = new AudioDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia), _visibleSystemSounds);

// TODO: We are getting crashes sometimes caused by the key already existing. This should never happen since Stop should always be called
// before Start but for some reason it is happening.
if(_devices.ContainsKey(device.ID))
{
_devices[device.ID].Dispose();
_devices.Remove(device.ID);
}
Stop();

_devices.Add(device.ID, device);
OnSessionCreated(device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ private Task<string> DiscoverAsync()
private string Discover()
{
string[] portNames;
var result = string.Empty;

try { portNames = SerialPort.GetPortNames(); }
catch { return result; }
catch { return string.Empty; }

SerialPort serialPort = null;
foreach (var portName in portNames)
Expand All @@ -98,22 +97,19 @@ private string Discover()
serialPort.Open();

Send(serialPort);
}
catch { continue; }

try
{
if (Receive(serialPort))
{
result = portName;
serialPort.Close();
break;
return portName;
}

serialPort.Close();
}
catch { continue; }
catch { }
}

return result;
return string.Empty;
}

private void Send(SerialPort serialPort)
Expand Down

0 comments on commit a81f70c

Please sign in to comment.