UWP kiosk mode app (Task problems)

1

I have a running uwp app. Now I want to run it in win 10 kiosk mode to avoid that the users can close the app.

My app structure is like followes:

SplashScreen (LoadingScreen) where I start a awaited task to load all the data form network (approx. 5 min loading). If loading finished I raise an event and display the MainPage on MainView dispatcher thread.

All this is working for normal app.

But in kiosk mode the app is running on an different layer: https://msdn.microsoft.com/library/windows/hardware/mt633799(v=vs.85).aspx

If I start the app in kiosk mode i get a black screen. So I changed the call of the task in SplashScreen. But now I can't go to MainPage if the ecent raises (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

SplashScreen:

public sealed partial class Splash : Page {
        public Splash(SplashScreen splashscreen, bool loadState) {
            InitializeComponent();

            SharePointDataSource.SharePointDataSourceLoaded += DataLoaded;

            // Create a Frame to act as the navigation context 
            rootFrame = new Frame();
        }

        // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
        void DismissedEventHandler(SplashScreen sender, object e) {
            LoadSharePointDataSource();
        }

        private async void LoadSharePointDataSource()
        {
            await SharePointDataSource.GetMainGroupsAsync();
            await SharePointDataSource.GetShortcutItemsAsync();
        }

        // Old Solution: Run on UI Threads
        //private async void LoadSharePointDataSource() {
        //    try {
        //        await ExecuteOnUiThread(() =>
        //        {
        //            SharePointDataSource.GetMainGroupsAsync();
        //            SharePointDataSource.GetShortcutItemsAsync();
        //        });
        //    }
        //    catch (Exception e)
        //    {
        //        .....
        //    }
        //}

        //public async Task<IAsyncAction> ExecuteOnUiThread(DispatchedHandler action) {
        //    return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, action);
        //    // do not work
        //    //return CoreApplication.GetCurrentView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, action);
        //}

        private void DataLoaded(object sender, object o) {
            DismissExtendedSplash();
        }

        // Goto main page
        void DismissExtendedSplash() {
            //// Navigate to mainpage
            rootFrame.Navigate(typeof(MainItemsPage));
            //// Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
    }
}

SharePointDataSource:

public sealed class SharePointDataSource {    
        // Event if loading finished
        public static event EventHandler SharePointDataSourceLoaded;

        // Singleton
        private static readonly Lazy<SharePointDataSource> instance = new Lazy<SharePointDataSource>(() => new SharePointDataSource());

        public static SharePointDataSource Instance {
            get {
                return instance.Value;
            }
        }

        private void OnSharePointDataSourceLoaded() {
            EventHandler eventHandler = SharePointDataSourceLoaded;
            if (eventHandler != null) {
                eventHandler(this, new EventArgs());
            }
        }

        public static async Task<IEnumerable<MainDataGroup>> GetMainGroupsAsync() {
            await Instance.GetMainGroupDataAsync();
            return Instance.MainGroups;
        }

        private async Task GetMainGroupDataAsync() {
            // DO data loading from network
            .....   
            OnSharePointDataSourceLoaded();
        }
}

I think the problems are the different tasks/threads. But I don't know how I can handle this clean!?

c#
windows-runtime
win-universal-app
asked on Stack Overflow May 10, 2016 by GermanSniper

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0