@@ -51,7 +51,7 @@ public bool ThreadListAlignRight
51
51
private AsyncLock ActionInProgress = new AsyncLock ( ) ;
52
52
public MainPage View ;
53
53
public SignalConversation SelectedThread ;
54
- private volatile bool Running = true ;
54
+ private volatile bool Running = false ;
55
55
private Task IncomingMessagesTask ;
56
56
private Task OutgoingMessagesTask ;
57
57
private CancellationTokenSource CancelSource ;
@@ -105,13 +105,22 @@ public MainPageViewModel()
105
105
App . MainPageActive = true ;
106
106
}
107
107
108
+ public async Task OnNavigatedTo ( )
109
+ {
110
+ if ( ! Running )
111
+ {
112
+ await Init ( ) ;
113
+ }
114
+ }
115
+
108
116
public async Task Init ( )
109
117
{
110
- CancelSource = new CancellationTokenSource ( ) ;
111
118
Debug . WriteLine ( "Init lock wait" ) ;
112
119
using ( await ActionInProgress . LockAsync ( CancelSource . Token ) )
113
120
{
114
121
Debug . WriteLine ( "Init lock grabbed" ) ;
122
+ Running = true ;
123
+ CancelSource = new CancellationTokenSource ( ) ;
115
124
try
116
125
{
117
126
await Task . Run ( async ( ) =>
@@ -176,6 +185,8 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
176
185
catch ( AuthorizationFailedException )
177
186
{
178
187
Debug . WriteLine ( "OWS server rejected our credentials - redirecting to StartPage" ) ;
188
+ Running = false ;
189
+ CancelSource . Cancel ( ) ;
179
190
View . Frame . Navigate ( typeof ( StartPage ) ) ;
180
191
}
181
192
catch ( Exception e )
@@ -189,11 +200,11 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
189
200
190
201
public async Task Shutdown ( )
191
202
{
192
- Running = false ;
193
- App . MainPageActive = false ;
194
203
Debug . WriteLine ( "Shutdown lock await" ) ;
195
204
using ( await ActionInProgress . LockAsync ( ) )
196
205
{
206
+ Running = false ;
207
+ App . MainPageActive = false ;
197
208
Debug . WriteLine ( "Shutdown lock grabbed" ) ;
198
209
CancelSource . Cancel ( ) ;
199
210
await IncomingMessagesTask ;
0 commit comments