@@ -71,8 +71,10 @@ public void AddThread(SignalConversation contact)
71
71
72
72
internal async void BackButton_Click ( object sender , BackRequestedEventArgs e )
73
73
{
74
+ Debug . WriteLine ( "MPVMBack lock wait" ) ;
74
75
using ( await ActionInProgress . LockAsync ( ) )
75
76
{
77
+ Debug . WriteLine ( "MPVMBack lock grabbed" ) ;
76
78
SelectedThread = null ;
77
79
View . Thread . DisposeCurrentThread ( ) ;
78
80
ThreadVisibility = Visibility . Collapsed ;
@@ -81,6 +83,7 @@ internal async void BackButton_Click(object sender, BackRequestedEventArgs e)
81
83
Utils . DisableBackButton ( BackButton_Click ) ;
82
84
e . Handled = true ;
83
85
}
86
+ Debug . WriteLine ( "MPVMBack lock released" ) ;
84
87
}
85
88
86
89
public void UIUpdateThread ( SignalConversation thread )
@@ -104,92 +107,98 @@ public MainPageViewModel()
104
107
public async Task Init ( )
105
108
{
106
109
CancelSource = new CancellationTokenSource ( ) ;
107
- var l = ActionInProgress . Lock ( CancelSource . Token ) ;
108
- try
110
+ Debug . WriteLine ( "Init lock wait" ) ;
111
+ using ( await ActionInProgress . LockAsync ( CancelSource . Token ) )
109
112
{
110
- await Task . Run ( async ( ) =>
113
+ Debug . WriteLine ( "Init lock grabbed" ) ;
114
+ try
111
115
{
112
- SignalDBContext . FailAllPendingMessages ( ) ;
113
- List < SignalContact > contacts = SignalDBContext . GetAllContactsLocked ( ) ;
114
- List < SignalGroup > groups = SignalDBContext . GetAllGroupsLocked ( ) ;
115
- await Windows . ApplicationModel . Core . CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( Windows . UI . Core . CoreDispatcherPriority . Normal , ( ) =>
116
+ await Task . Run ( async ( ) =>
116
117
{
117
- try
118
+ SignalDBContext . FailAllPendingMessages ( ) ;
119
+ List < SignalContact > contacts = SignalDBContext . GetAllContactsLocked ( ) ;
120
+ List < SignalGroup > groups = SignalDBContext . GetAllGroupsLocked ( ) ;
121
+ await Windows . ApplicationModel . Core . CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( Windows . UI . Core . CoreDispatcherPriority . Normal , ( ) =>
118
122
{
119
- int amountContacts = contacts . Count ;
120
- int amountGroups = groups . Count ;
121
- int contactsIdx = 0 ;
122
- int groupsIdx = 0 ;
123
- while ( contactsIdx < amountContacts || groupsIdx < amountGroups )
123
+ try
124
124
{
125
- if ( contactsIdx < amountContacts )
125
+ int amountContacts = contacts . Count ;
126
+ int amountGroups = groups . Count ;
127
+ int contactsIdx = 0 ;
128
+ int groupsIdx = 0 ;
129
+ while ( contactsIdx < amountContacts || groupsIdx < amountGroups )
126
130
{
127
- SignalConversation contact = contacts [ contactsIdx ] ;
128
- if ( groupsIdx < amountGroups )
131
+ if ( contactsIdx < amountContacts )
129
132
{
130
- SignalConversation group = groups [ groupsIdx ] ;
131
- if ( contact . LastActiveTimestamp > group . LastActiveTimestamp )
133
+ SignalConversation contact = contacts [ contactsIdx ] ;
134
+ if ( groupsIdx < amountGroups )
132
135
{
133
- contactsIdx ++ ;
134
- AddThread ( contact ) ;
136
+ SignalConversation group = groups [ groupsIdx ] ;
137
+ if ( contact . LastActiveTimestamp > group . LastActiveTimestamp )
138
+ {
139
+ contactsIdx ++ ;
140
+ AddThread ( contact ) ;
141
+ }
142
+ else
143
+ {
144
+ groupsIdx ++ ;
145
+ AddThread ( group ) ;
146
+ }
135
147
}
136
148
else
137
149
{
138
- groupsIdx ++ ;
139
- AddThread ( group ) ;
150
+ contactsIdx ++ ;
151
+ AddThread ( contact ) ;
140
152
}
141
153
}
142
- else
154
+ else if ( groupsIdx < amountGroups )
143
155
{
144
- contactsIdx ++ ;
145
- AddThread ( contact ) ;
156
+ SignalConversation group = groups [ groupsIdx ] ;
157
+ groupsIdx ++ ;
158
+ AddThread ( group ) ;
146
159
}
147
160
}
148
- else if ( groupsIdx < amountGroups )
149
- {
150
- SignalConversation group = groups [ groupsIdx ] ;
151
- groupsIdx ++ ;
152
- AddThread ( group ) ;
153
- }
154
161
}
155
- }
156
- catch ( Exception e )
157
- {
158
- Debug . WriteLine ( e . Message ) ;
159
- Debug . WriteLine ( e . StackTrace ) ;
160
- }
162
+ catch ( Exception e )
163
+ {
164
+ Debug . WriteLine ( e . Message ) ;
165
+ Debug . WriteLine ( e . StackTrace ) ;
166
+ }
167
+ } ) ;
168
+ MessageReceiver = new SignalServiceMessageReceiver ( CancelSource . Token , App . ServiceUrls , new StaticCredentialsProvider ( App . Store . Username , App . Store . Password , App . Store . SignalingKey , ( int ) App . Store . DeviceId ) , App . USER_AGENT ) ;
169
+ Pipe = MessageReceiver . createMessagePipe ( ) ;
170
+ MessageSender = new SignalServiceMessageSender ( CancelSource . Token , App . ServiceUrls , App . Store . Username , App . Store . Password , ( int ) App . Store . DeviceId , new Store ( ) , Pipe , null , App . USER_AGENT ) ;
171
+ IncomingMessagesTask = Task . Factory . StartNew ( HandleIncomingMessages , TaskCreationOptions . LongRunning ) ;
172
+ OutgoingMessagesTask = Task . Factory . StartNew ( HandleOutgoingMessages , TaskCreationOptions . LongRunning ) ;
161
173
} ) ;
162
- MessageReceiver = new SignalServiceMessageReceiver ( CancelSource . Token , App . ServiceUrls , new StaticCredentialsProvider ( App . Store . Username , App . Store . Password , App . Store . SignalingKey , ( int ) App . Store . DeviceId ) , App . USER_AGENT ) ;
163
- Pipe = MessageReceiver . createMessagePipe ( ) ;
164
- MessageSender = new SignalServiceMessageSender ( CancelSource . Token , App . ServiceUrls , App . Store . Username , App . Store . Password , ( int ) App . Store . DeviceId , new Store ( ) , Pipe , null , App . USER_AGENT ) ;
165
- IncomingMessagesTask = Task . Factory . StartNew ( HandleIncomingMessages , TaskCreationOptions . LongRunning ) ;
166
- OutgoingMessagesTask = Task . Factory . StartNew ( HandleOutgoingMessages , TaskCreationOptions . LongRunning ) ;
167
- } ) ;
168
- }
169
- catch ( AuthorizationFailedException )
170
- {
171
- Debug . WriteLine ( "OWS server rejected our credentials - redirecting to StartPage" ) ;
172
- View . Frame . Navigate ( typeof ( StartPage ) ) ;
173
- }
174
- catch ( Exception e )
175
- {
176
- Debug . WriteLine ( e . Message ) ;
177
- Debug . WriteLine ( e . StackTrace ) ;
178
- }
179
- finally
180
- {
181
- l . Dispose ( ) ;
174
+ }
175
+ catch ( AuthorizationFailedException )
176
+ {
177
+ Debug . WriteLine ( "OWS server rejected our credentials - redirecting to StartPage" ) ;
178
+ View . Frame . Navigate ( typeof ( StartPage ) ) ;
179
+ }
180
+ catch ( Exception e )
181
+ {
182
+ Debug . WriteLine ( e . Message ) ;
183
+ Debug . WriteLine ( e . StackTrace ) ;
184
+ }
182
185
}
186
+ Debug . WriteLine ( "Init lock released" ) ;
183
187
}
184
188
185
189
public async Task Shutdown ( )
186
190
{
187
191
Running = false ;
188
192
App . MainPageActive = false ;
189
- var l = await ActionInProgress . LockAsync ( ) ;
190
- CancelSource . Cancel ( ) ;
191
- await IncomingMessagesTask ;
192
- await OutgoingMessagesTask ;
193
+ Debug . WriteLine ( "Shutdown lock await" ) ;
194
+ using ( await ActionInProgress . LockAsync ( ) )
195
+ {
196
+ Debug . WriteLine ( "Shutdown lock grabbed" ) ;
197
+ CancelSource . Cancel ( ) ;
198
+ await IncomingMessagesTask ;
199
+ await OutgoingMessagesTask ;
200
+ }
201
+ Debug . WriteLine ( "Shutdown lock released" ) ;
193
202
}
194
203
195
204
internal async void ContactsList_SelectionChanged ( object sender , SelectionChangedEventArgs e )
@@ -198,8 +207,10 @@ internal async void ContactsList_SelectionChanged(object sender, SelectionChange
198
207
{
199
208
try
200
209
{
210
+ Debug . WriteLine ( "SelectionChanged lock await" ) ;
201
211
using ( await ActionInProgress . LockAsync ( ) )
202
212
{
213
+ Debug . WriteLine ( "SelectionChanged lock grabbed" ) ;
203
214
WelcomeVisibility = Visibility . Collapsed ;
204
215
ThreadVisibility = Visibility . Visible ;
205
216
SelectedThread = ( SignalConversation ) e . AddedItems [ 0 ] ;
@@ -212,6 +223,7 @@ internal async void ContactsList_SelectionChanged(object sender, SelectionChange
212
223
UIResetRead ( conversation ) ;
213
224
View . Thread . ScrollToBottom ( ) ;
214
225
}
226
+ Debug . WriteLine ( "SelectionChanged lock released" ) ;
215
227
}
216
228
catch ( Exception ex )
217
229
{
@@ -244,8 +256,10 @@ internal async Task TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
244
256
Read = true ,
245
257
Type = SignalMessageType . Normal
246
258
} ;
259
+ Debug . WriteLine ( "keydown lock await" ) ;
247
260
using ( await ActionInProgress . LockAsync ( ) )
248
261
{
262
+ Debug . WriteLine ( "keydown lock grabbed" ) ;
249
263
View . Thread . Append ( message ) ;
250
264
View . Thread . ScrollToBottom ( ) ;
251
265
SelectedThread . LastMessage = message ;
@@ -267,6 +281,7 @@ await Task.Run(() =>
267
281
Debug . WriteLine ( "ms until out queue: " + ( after - now ) ) ;
268
282
View . Thread . RemoveUnreadMarker ( ) ;
269
283
}
284
+ Debug . WriteLine ( "keydown lock released" ) ;
270
285
}
271
286
}
272
287
}
@@ -300,8 +315,10 @@ public void MoveThreadToTop(SignalConversation thread)
300
315
301
316
public async Task UIHandleIncomingMessage ( SignalMessage message )
302
317
{
318
+ Debug . WriteLine ( "incoming lock await" ) ;
303
319
using ( await ActionInProgress . LockAsync ( ) )
304
320
{
321
+ Debug . WriteLine ( "incoming lock grabbed" ) ;
305
322
var thread = ThreadsDictionary [ message . ThreadId ] ;
306
323
uint unreadCount = thread . UnreadCount ;
307
324
if ( SelectedThread == thread )
@@ -351,6 +368,7 @@ await Task.Run(() =>
351
368
thread . View . UpdateConversationDisplay ( thread ) ;
352
369
MoveThreadToTop ( thread ) ;
353
370
}
371
+ Debug . WriteLine ( "incoming lock released" ) ;
354
372
}
355
373
356
374
public void UIResetRead ( SignalConversation conversation )
@@ -371,8 +389,10 @@ public void UIUpdateMessageBox(SignalMessage updatedMessage)
371
389
372
390
public async Task UIHandleIdentityKeyChange ( string number )
373
391
{
392
+ Debug . WriteLine ( "IKChange lock await" ) ;
374
393
using ( await ActionInProgress . LockAsync ( ) )
375
394
{
395
+ Debug . WriteLine ( "IKChange lock grabbed" ) ;
376
396
var messages = SignalDBContext . InsertIdentityChangedMessages ( number ) ;
377
397
foreach ( var message in messages )
378
398
{
@@ -387,6 +407,7 @@ public async Task UIHandleIdentityKeyChange(string number)
387
407
thread . View . UpdateConversationDisplay ( thread ) ;
388
408
}
389
409
}
410
+ Debug . WriteLine ( "IKChange lock released" ) ;
390
411
}
391
412
392
413
#endregion UIThread
0 commit comments