C# UWP信息亭模式应用程序(任务问题)
我有一个正在运行的uwp应用程序。现在我想在win 10 kiosk模式下运行它,以避免用户关闭应用程序 我的应用程序结构如下所示: SplashScreen(LoadingScreen),在这里我启动了一个等待的任务,以加载网络中的所有数据(加载约5分钟)。 如果加载完成,我将引发一个事件并在MainView dispatcher线程上显示主页面 所有这些都适用于普通应用程序 但在kiosk模式下,应用程序运行在不同的层上: 如果我在kiosk模式下启动应用程序,我会看到一个黑屏。所以我在SplashScreen中更改了任务的调用。但现在,如果ecent引发异常,我就无法转到主页面(来自HRESULT的异常:0x8001010E(RPC_E_错误的_线程)) 溅屏:C# UWP信息亭模式应用程序(任务问题),c#,windows-runtime,win-universal-app,C#,Windows Runtime,Win Universal App,我有一个正在运行的uwp应用程序。现在我想在win 10 kiosk模式下运行它,以避免用户关闭应用程序 我的应用程序结构如下所示: SplashScreen(LoadingScreen),在这里我启动了一个等待的任务,以加载网络中的所有数据(加载约5分钟)。 如果加载完成,我将引发一个事件并在MainView dispatcher线程上显示主页面 所有这些都适用于普通应用程序 但在kiosk模式下,应用程序运行在不同的层上: 如果我在kiosk模式下启动应用程序,我会看到一个黑屏。所以我在Sp
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;
}
}
}
公共密封部分类启动:第页{
公共闪屏(闪屏闪屏、bool loadState){
初始化组件();
SharePointDataSource.SharePointDataSourceLoaded+=DataLoaded;
//创建一个框架作为导航上下文
rootFrame=新框架();
}
//包括系统从初始屏幕转换到扩展初始屏幕(应用程序的第一个视图)时要执行的代码。
void dismissedenthandler(飞溅屏幕发送器,对象e){
LoadSharePointDataSource();
}
私有异步void LoadSharePointDataSource()
{
等待SharePointDataSource.GetMainGroupsAsync();
等待SharePointDataSource.GetShortcutItemsAsync();
}
//旧的解决方案:在UI线程上运行
//私有异步void LoadSharePointDataSource(){
//试一试{
//等待ExecuteonuThread(()=>
// {
//SharePointDataSource.GetMainGroupsAsync();
//SharePointDataSource.GetShortcutItemsAsync();
// });
// }
//捕获(例外e)
// {
// .....
// }
//}
//公共异步任务ExecuteUnuithread(DispatchedHandler操作){
//返回CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,action);
////不工作
////返回CoreApplication.GetCurrentView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal,action);
//}
已加载私有void数据(对象发送方、对象o){
DismissExtendedSplash();
}
//转到主页
void DismissExtendedSplash(){
////导航到主页
rootFrame.Navigate(typeof(MainItemsPage));
////将框架放置在当前窗口中
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();
}
}
公共密封类SharePointDataSource{
//事件(如果加载完成)
公共静态事件事件处理程序SharePointDataSourceLoaded;
//独生子女
private static readonly Lazy instance=new Lazy(()=>new SharePointDataSource());
公共静态SharePointDataSource实例{
得到{
返回instance.Value;
}
}
SharePointDataSourceLoaded()上的私有void{
EventHandler EventHandler=SharePointDataSourceLoaded;
if(eventHandler!=null){
eventHandler(这是新的EventArgs());
}
}
公共静态异步任务GetMainGroupsAsync(){
等待实例。GetMainGroupDataAsync();
返回Instance.main组;
}
专用异步任务GetMainGroupDataAsync(){
//是否从网络加载数据
.....
OnSharePointDataSourceLoaded();
}
}
我认为问题在于不同的任务/线程。但我不知道我怎么能把这干净利落的处理好