Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 初始化MobileServicesClient的最佳位置_C#_Uwp_Azure Mobile Services - Fatal编程技术网

C# 初始化MobileServicesClient的最佳位置

C# 初始化MobileServicesClient的最佳位置,c#,uwp,azure-mobile-services,C#,Uwp,Azure Mobile Services,我正在尝试初始化MobileServices客户端的一个实例。我想在共享单例对象上创建一个实例,应用程序中的所有页面都可以使用它。我尝试在App.xaml.cs中的应用程序构造函数上初始化它,但遇到了一个令人讨厌的本机异常。初始化MobileServices客户端的最佳位置是什么 你主页的构造器 主页的已加载事件(执行空检查后) 已启动应用程序的事件处理程序 移动服务快速入门将其内联初始化为App.xaml.cs中的公共静态。例如: 然后,您可以从应用程序代码中以App.MobileServi

我正在尝试初始化MobileServices客户端的一个实例。我想在共享单例对象上创建一个实例,应用程序中的所有页面都可以使用它。我尝试在App.xaml.cs中的应用程序构造函数上初始化它,但遇到了一个令人讨厌的本机异常。初始化MobileServices客户端的最佳位置是什么

  • 你主页的构造器
  • 主页的已加载事件(执行空检查后)
  • 已启动应用程序的事件处理程序

移动服务快速入门将其内联初始化为App.xaml.cs中的公共静态。例如:


然后,您可以从应用程序代码中以App.MobileService
的形式访问它。

移动服务快速启动程序会在App.xaml.cs中将其内联初始化为公共静态。例如:


然后,您可以从应用程序代码中以App.MobileService
的形式访问它。

最好将其作为App.Xaml.cs中的静态变量,如下所示:

namespace myapp
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : Application
    {

        // This MobileServiceClient has been configured to communicate with the Azure Mobile App.
        // You're all set to start working with your Mobile App!
        public static MobileServiceClient MobileService = new MobileServiceClient("https://my-apservice.azurewebsites.net");
名称空间myapp
{
/// 
///提供特定于应用程序的行为以补充默认应用程序类。
/// 
密封部分类应用程序:应用程序
{
//此MobileServiceClient已配置为与Azure移动应用程序通信。
//您已准备好开始使用您的移动应用程序!
公共静态MobileServiceClient MobileService=新的MobileServiceClient(“https://my-apservice.azurewebsites.net");

然后,您可以使用App.MobileService访问客户端。最好的方法是将其作为App.Xaml.cs中的静态变量,如下所示:

namespace myapp
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : Application
    {

        // This MobileServiceClient has been configured to communicate with the Azure Mobile App.
        // You're all set to start working with your Mobile App!
        public static MobileServiceClient MobileService = new MobileServiceClient("https://my-apservice.azurewebsites.net");
名称空间myapp
{
/// 
///提供特定于应用程序的行为以补充默认应用程序类。
/// 
密封部分类应用程序:应用程序
{
//此MobileServiceClient已配置为与Azure移动应用程序通信。
//您已准备好开始使用您的移动应用程序!
公共静态MobileServiceClient MobileService=新的MobileServiceClient(“https://my-apservice.azurewebsites.net");
然后,您可以使用
App.MobileService
访问客户端