Now able to switch screens away from party without crashing

This commit is contained in:
watsonb8 2019-11-29 20:51:48 -05:00
parent ad1fca2009
commit e822829cc0
3 changed files with 21 additions and 24 deletions

View File

@ -48,6 +48,12 @@ namespace Aurora.Design.Views.Party
PlayCommand = new Command(OnDoubleClickExecute, CanDoubleClickExecute); PlayCommand = new Command(OnDoubleClickExecute, CanDoubleClickExecute);
_client = ClientService.Instance; _client = ClientService.Instance;
_client.OnMediaPaused += this.OnMediaPaused;
_client.OnMediaResumed += this.OnMediaResumed;
_client.OnNewMediaPlaying += this.OnNewMediaPlaying;
_client.OnPartyMemberJoined += this.OnPartyMemberJoined;
_client.OnPartyMemberLeft += this.OnPartyMemberLeft;
} }
~PartyViewModel() ~PartyViewModel()
@ -155,16 +161,11 @@ namespace Aurora.Design.Views.Party
/// <returns></returns> /// <returns></returns>
public override async Task OnActive() public override async Task OnActive()
{ {
//TODO if (this._state == PartyState.Hosting ||
if (this._state == PartyState.Hosting) this._state == PartyState.InParty)
{ {
await SubscribeToEvents(); await _client.GetEvents().ConfigureAwait(false);
} }
_client.OnMediaPaused += this.OnMediaPaused;
_client.OnMediaResumed += this.OnMediaResumed;
_client.OnNewMediaPlaying += this.OnNewMediaPlaying;
_client.OnPartyMemberJoined += this.OnPartyMemberJoined;
_client.OnPartyMemberLeft += this.OnPartyMemberLeft;
} }
/// <summary> /// <summary>
@ -174,14 +175,6 @@ namespace Aurora.Design.Views.Party
public override async Task OnInactive() public override async Task OnInactive()
{ {
_client.StopEvents(); _client.StopEvents();
await UnsubscribeFromEvents();
//Stop event stream and un hook events
_client.OnMediaPaused -= this.OnMediaPaused;
_client.OnMediaResumed -= this.OnMediaResumed;
_client.OnNewMediaPlaying -= this.OnNewMediaPlaying;
_client.OnPartyMemberJoined -= this.OnPartyMemberJoined;
_client.OnPartyMemberLeft -= this.OnPartyMemberLeft;
} }
/// <summary> /// <summary>

View File

@ -74,9 +74,6 @@ namespace Aurora.Services.ClientService
_remoteEventsClient = new RemoteEventService.RemoteEventServiceClient(_channel); _remoteEventsClient = new RemoteEventService.RemoteEventServiceClient(_channel);
_remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel); _remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel);
_remoteSyncClient = new RemoteSyncService.RemoteSyncServiceClient(_channel); _remoteSyncClient = new RemoteSyncService.RemoteSyncServiceClient(_channel);
//Assign but don't start task
_eventCancellationTokenSource = new CancellationTokenSource();
} }
public async void Close() public async void Close()
@ -96,6 +93,7 @@ namespace Aurora.Services.ClientService
/// <returns></returns> /// <returns></returns>
public async Task GetEvents() public async Task GetEvents()
{ {
_eventCancellationTokenSource = new CancellationTokenSource();
string clientId = SettingsService.Instance.ClientId; string clientId = SettingsService.Instance.ClientId;
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId)); Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId));
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient

View File

@ -181,18 +181,24 @@ namespace Aurora.Services.EventManager
if (actionsCopy.ContainsKey(pair.Key)) if (actionsCopy.ContainsKey(pair.Key))
{ {
actionsCopy.TryGetValue(pair.Key, out Action<BaseEvent> action); actionsCopy.TryGetValue(pair.Key, out Action<BaseEvent> action);
Task executionTask = new Task(() => action(bEvent));
executionTask.ContinueWith((Task task) => ExceptionHandler(task, pair.Key),
TaskContinuationOptions.OnlyOnFaulted);
ParameterizedThreadStart operation = new ParameterizedThreadStart(obj => action((BaseEvent)obj)); executionTask.Start();
Thread executionThread = new Thread(operation, 1024 * 1024);
executionThread.Start(bEvent);
executionThread.Join();
} }
} }
} }
} }
private void ExceptionHandler(Task executionTask, string actionKey)
{
var exception = executionTask.Exception;
Console.WriteLine(string.Format("SERVER --- Exception occurred firing event"));
this._actionList.Remove(actionKey);
}
#endregion Public Methods #endregion Public Methods
} }