UWP自助服务终端模式应用程序(任务问题)

时间:2016-05-10 06:29:52

标签: c# windows-runtime win-universal-app

我有一个正在运行的uwp应用程序。现在我想在win 10 kiosk模式下运行它,以避免用户关闭应用程序。

我的应用结构如下:

SplashScreen(LoadingScreen)我开始等待的任务,从网络加载所有数据(加载约5分钟)。 如果加载完成,我引发一个事件并在MainView调度程序线程上显示MainPage。

所有这些都适用于普通应用。

但在自助服务终端模式下,该应用正在另一层运行:https://msdn.microsoft.com/library/windows/hardware/mt633799(v=vs.85).aspx

如果我在自助服务终端模式下启动应用程序,则会出现黑屏。所以我改变了SplashScreen中任务的调用。但是现在如果ecent引发我无法进入MainPage(HRESULT异常:0x8001010E(RPC_E_WRONG_THREAD))

闪屏:

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();
        }
}

我认为问题是不同的任务/线程。但我不知道如何处理这个问题!?

0 个答案:

没有答案