1

我开始将 windows phone 7 应用程序移植到 windows 8,他们使用 IApplicationService 继承类来启动停止服务。我如何在 Windows 8 中实现相同的功能。我在下面附上了 Windows 电话代码。请帮我。它的阻塞部分似乎有点困难。

      public class ApplicationService : IApplicationService
      {
           private IApplicationService _logger;
           private IApplicationService _dataSourceManager;
           public void StartService(ApplicationServiceContext context)
           {
                  _logger = new Logger();
                  _dataSourceManager = new DataSourceManager();
                  _logger.StartService(context);
                  _dataSourceManager.StartService(context);
           }  
           private IApplicationService LoadService(string assemblyName, string typename)
           {
                    var parts = Deployment.Current.Parts;
                    if (parts.Any(part => part.Source.StartsWith(assemblyName)))
                    {
                             var assembly = Assembly.Load(assemblyName);
                             Type type = assembly.GetType(typename);
                             return Activator.CreateInstance(type, new[] {   
                             SynchronizationContext.Current }) as IApplicationService;
                    }
                    return null;
           }
           public void StopService()
          {
                  Current.StopService();
                 _dataSourceManager.StopService();
                 _logger.StopService(); // stop last because other services depend on it
                 _logger = null;
                 _dataSourceManager = null;
           }
}
4

0 回答 0