1111using Newtonsoft . Json ;
1212using Newtonsoft . Json . Linq ;
1313using TinCan ;
14+ #if NETSTANDARD
1415using Xamarin . Forms ;
16+ #else
17+ using Microsoft . Maui ;
18+ using Microsoft . Maui . ApplicationModel ;
19+ using Microsoft . Maui . Controls ;
20+ #endif
1521
1622namespace Float . TinCan . ActivityLibrary
1723{
@@ -111,7 +117,7 @@ public override void Start()
111117 }
112118 else
113119 {
114- Device . BeginInvokeOnMainThread ( async ( ) =>
120+ Action mainThreadCode = async ( ) =>
115121 {
116122 try
117123 {
@@ -129,7 +135,12 @@ public override void Start()
129135 downloadStatus . DownloadsCompleted += HandleDownloadCompleted ;
130136 downloadStatus . DownloadsCancelled += HandleDownloadCancelled ;
131137 await ShowDownloadStatus ( CreateDownloadStatusPage ( downloadStatus ) ) ;
132- } ) ;
138+ } ;
139+ #if NETSTANDARD
140+ Device . BeginInvokeOnMainThread ( mainThreadCode ) ;
141+ #else
142+ MainThread . BeginInvokeOnMainThread ( mainThreadCode ) ;
143+ #endif
133144 }
134145 }
135146
@@ -243,11 +254,16 @@ protected virtual void OnActivityFinished(object sender, EventArgs args)
243254 /// </summary>
244255 protected void ShowCompletionScreen ( )
245256 {
246- Device . BeginInvokeOnMainThread ( async ( ) =>
257+ Action mainThreadCode = async ( ) =>
247258 {
248259 var completionPage = CreateActivityCompletePage ( AvailablePostAssessments != null && AvailablePostAssessments . Any ( ) ) ;
249260 await NavigationContext . PresentPageAsync ( completionPage ) ;
250- } ) ;
261+ } ;
262+ #if NETSTANDARD
263+ Device . BeginInvokeOnMainThread ( mainThreadCode ) ;
264+ #else
265+ MainThread . BeginInvokeOnMainThread ( mainThreadCode ) ;
266+ #endif
251267 }
252268
253269 /// <summary>
@@ -273,10 +289,15 @@ protected virtual void HandleCancelDownloadRequested(object sender, EventArgs ar
273289 /// <param name="args">Arguments related to the event.</param>
274290 protected virtual void HandleActivityFinished ( object sender , EventArgs args )
275291 {
276- Device . BeginInvokeOnMainThread ( ( ) =>
292+ Action mainThreadCode = ( ) =>
277293 {
278294 this . Activity . CompletionDate = DateTimeOffset . Now ;
279- } ) ;
295+ } ;
296+ #if NETSTANDARD
297+ Device . BeginInvokeOnMainThread ( mainThreadCode ) ;
298+ #else
299+ MainThread . BeginInvokeOnMainThread ( mainThreadCode ) ;
300+ #endif
280301
281302 if ( args is not StatementEventArgs statementArgs )
282303 {
@@ -319,10 +340,15 @@ protected virtual void HandleActivityProgressed(object sender, EventArgs args)
319340 return ;
320341 }
321342
322- Device . BeginInvokeOnMainThread ( ( ) =>
343+ Action mainThreadCode = ( ) =>
323344 {
324345 this . Activity . PercentComplete = ( double ) percentComplete / 100 ;
325- } ) ;
346+ } ;
347+ #if NETSTANDARD
348+ Device . BeginInvokeOnMainThread ( mainThreadCode ) ;
349+ #else
350+ MainThread . BeginInvokeOnMainThread ( mainThreadCode ) ;
351+ #endif
326352 }
327353
328354 /// <summary>
@@ -414,7 +440,7 @@ protected virtual void HandleDownloadError(object sender, EventArgs args)
414440
415441 void CreateRunnerAndHandleErrors ( )
416442 {
417- Device . BeginInvokeOnMainThread ( async ( ) =>
443+ Action mainThreadCode = async ( ) =>
418444 {
419445 try
420446 {
@@ -427,7 +453,12 @@ void CreateRunnerAndHandleErrors()
427453 OnActivityLaunchException ( e ) ;
428454 Finish ( EventArgs . Empty ) ;
429455 }
430- } ) ;
456+ } ;
457+ #if NETSTANDARD
458+ Device . BeginInvokeOnMainThread ( mainThreadCode ) ;
459+ #else
460+ MainThread . BeginInvokeOnMainThread ( mainThreadCode ) ;
461+ #endif
431462 }
432463
433464 /// <summary>
0 commit comments