我开始将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;
}
}