我怎样才能让我的Windows商店应用的名称和版本信息? [英] How can I get my Windows Store app's title and version info?

查看:122
本文介绍了我怎样才能让我的Windows商店应用的名称和版本信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码工作正常,在我的WP8应用程序:

This code works fine in my WP8 app:

void App_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
    string appName;
    string appVersion;
    var xmlReaderSettings = new XmlReaderSettings
    {
        XmlResolver = new XmlXapResolver()
    };

    using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
    {
        xmlReader.ReadToDescendant("App");

        appName = xmlReader.GetAttribute("Title");
        appVersion = xmlReader.GetAttribute("Version");
    }

    WAMS_EXCEPTIONLOG wamsel = new WAMS_EXCEPTIONLOG
    {
        appNameAndVersion =
            string.Format("{0} {1}", appName,
                          appVersion),
        ExceptionMsg =
            args.ExceptionObject.Message,
        InnerException =
            args.ExceptionObject
                .InnerException.ToString(),
        ExceptionToStr =
            args.ExceptionObject.ToString(),
        dateTimeOffsetStamp =
            DateTimeOffset.UtcNow
    };
    await MobileService.GetTable<TASLS_WAMS_EXCEPTIONLOG>().InsertAsync(wamsel);
}



......但在我的Windows互补商店应用,有几个类和类成员是无法识别的,即:

...but in my complementary Windows store app, several classes and class members are unrecognized, to wit:

XmlResolver
XmlXapResolver
args.ExceptionObject

(更不用说加入异步的事件处理程序等待着是不允许的事实,并导致事件处理的分配去红)...

(not to mention the fact that await is not allowed, and adding "async" to the event handler causes the assignment of the event handler to "go red")...

所以,要回主穴:我怎样才能实现我得到我的WP8应用程序具有相同功能我的Windows商店应用

So, to get back to the main point: How can I achieve the same functionality I'm getting with my WP8 app with my Windows Store app?

推荐答案

让我先解决你的问题:


  • 有没有必要直接从XML阅读药品的信息,您可以使用的PackageId类来代替。

  • 的异常信息都存储在 args.Exception

  • 您还可以从事件处理异步方法通过把异步无效方法签名,但你必须记住,在方法将在被称为射后不理的模式,即应用程序不会等待异步方法complete.This不应该是一个问题,如果你设置 args.Handled = TRUE ,从而阻止应用结束

  • There is no need to read the package info directly from XML, you can use the PackageId class instead.
  • Exception info is stored in args.Exception.
  • You can call asynchronous methods from the event handler by putting async void in the method signature but you must keep in mind that the method will be called in "fire and forget" mode, i.e. the app won't wait for the asynchronous method to complete.This shouldn't be a problem if you set args.Handled = true and thus prevent the app from closing.

您固定的事件处理程序应该是这样的:

Your fixed event handler should look like this:

private async void App_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
    string appName = Package.Current.Id.Name;
    var version = Package.Current.Id.Version;
    string appVersion = String.Format("{0}.{1}.{2}.{3}", 
        version.Major, version.Minor, version.Build, version.Revision);

    WAMS_EXCEPTIONLOG wamsel = new WAMS_EXCEPTIONLOG
    {
        appNameAndVersion = string.Format("{0} {1}", appName, appVersion),
        ExceptionMsg = args.Exception.Message,
        InnerException = args.Exception.InnerException.ToString(),
        ExceptionToStr = args.Exception.ToString(),
        dateTimeOffsetStamp = DateTimeOffset.UtcNow
    };
    args.Handled = true;
    await MobileService.GetTable<TASLS_WAMS_EXCEPTIONLOG>().InsertAsync(wamsel);
}

您也应该检查是否 args.Exception.InnerException 为空,调用的ToString()上它。

You should also check if args.Exception.InnerException is null, before calling ToString() on it.

这篇关于我怎样才能让我的Windows商店应用的名称和版本信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆