Now able to switch screens away from party without crashing
This commit is contained in:
parent
ad1fca2009
commit
e822829cc0
@ -48,6 +48,12 @@ namespace Aurora.Design.Views.Party
|
||||
PlayCommand = new Command(OnDoubleClickExecute, CanDoubleClickExecute);
|
||||
|
||||
_client = ClientService.Instance;
|
||||
|
||||
_client.OnMediaPaused += this.OnMediaPaused;
|
||||
_client.OnMediaResumed += this.OnMediaResumed;
|
||||
_client.OnNewMediaPlaying += this.OnNewMediaPlaying;
|
||||
_client.OnPartyMemberJoined += this.OnPartyMemberJoined;
|
||||
_client.OnPartyMemberLeft += this.OnPartyMemberLeft;
|
||||
}
|
||||
|
||||
~PartyViewModel()
|
||||
@ -155,16 +161,11 @@ namespace Aurora.Design.Views.Party
|
||||
/// <returns></returns>
|
||||
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>
|
||||
@ -174,14 +175,6 @@ namespace Aurora.Design.Views.Party
|
||||
public override async Task OnInactive()
|
||||
{
|
||||
_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>
|
||||
|
@ -74,9 +74,6 @@ namespace Aurora.Services.ClientService
|
||||
_remoteEventsClient = new RemoteEventService.RemoteEventServiceClient(_channel);
|
||||
_remotePlaybackClient = new RemotePlaybackService.RemotePlaybackServiceClient(_channel);
|
||||
_remoteSyncClient = new RemoteSyncService.RemoteSyncServiceClient(_channel);
|
||||
|
||||
//Assign but don't start task
|
||||
_eventCancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public async void Close()
|
||||
@ -96,6 +93,7 @@ namespace Aurora.Services.ClientService
|
||||
/// <returns></returns>
|
||||
public async Task GetEvents()
|
||||
{
|
||||
_eventCancellationTokenSource = new CancellationTokenSource();
|
||||
string clientId = SettingsService.Instance.ClientId;
|
||||
Console.WriteLine(string.Format("CLIENT {0} - GetEvents called from client with id", clientId));
|
||||
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
|
||||
|
@ -181,18 +181,24 @@ namespace Aurora.Services.EventManager
|
||||
if (actionsCopy.ContainsKey(pair.Key))
|
||||
{
|
||||
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));
|
||||
Thread executionThread = new Thread(operation, 1024 * 1024);
|
||||
|
||||
executionThread.Start(bEvent);
|
||||
executionThread.Join();
|
||||
executionTask.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user