Skip to content

Commit

Permalink
Makes the tray icon always uses the main thread to interact with UI. …
Browse files Browse the repository at this point in the history
…See #41
  • Loading branch information
Antoine Aflalo committed Dec 18, 2015
1 parent 7838d5c commit 83fa139
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions SoundSwitch/Util/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public sealed class TrayIcon : IDisposable
{
private readonly ContextMenuStrip _selectionMenu = new ContextMenuStrip();
private readonly ContextMenuStrip _settingsMenu = new ContextMenuStrip();
private SynchronizationContext _context = SynchronizationContext.Current ?? new SynchronizationContext();

private readonly SynchronizationContext _context = SynchronizationContext.Current ?? new SynchronizationContext();
private readonly NotifyIcon _trayIcon = new NotifyIcon
{
Icon = Icon.FromHandle(Resources.SoundSwitch16.GetHicon()),
Expand Down Expand Up @@ -129,10 +128,10 @@ private void SetEventHandlers()
switch (audioDeviceType)
{
case AudioDeviceType.Playback:
ShowPlaybackChanged(audioChangeEvent.device.FriendlyName);
_context.Send(s => { ShowPlaybackChanged(audioChangeEvent.device.FriendlyName); }, null);
break;
case AudioDeviceType.Recording:
ShowRecordingChanged(audioChangeEvent.device.FriendlyName);
_context.Send(s => { ShowRecordingChanged(audioChangeEvent.device.FriendlyName); }, null);
break;
default:
throw new ArgumentOutOfRangeException();
Expand All @@ -144,14 +143,7 @@ private void SetEventHandlers()
(sender, deviceListChanged) => { _context.Send(s => { UpdateDeviceSelectionList(); }, null); };
AppModel.Instance.NewVersionReleased += (sender, @event) =>
{
if (_selectionMenu.IsHandleCreated)
{
_selectionMenu.Invoke(new Action(() => { NewReleaseAvailable(sender, @event); }));
}
else
{
NewReleaseAvailable(sender, @event);
}
_context.Send(s => { NewReleaseAvailable(sender, @event); }, null);
};

AppModel.Instance.DeviceRemoved +=
Expand Down

0 comments on commit 83fa139

Please sign in to comment.