【发布时间】:2016-06-15 20:51:32
【问题描述】:
我有一个包含 3 个项目的解决方案,
- MainProject(UWP 应用程序)
- 通用(类库)
- 后台服务(Windows 运行时应用程序)
MainProject 引用 Common 和 Background Services,Background Services 引用 Common。
我还有一个存储在 Common 中的单例类。当从 MainProject 引用时,单例类可以正常工作,但是当我尝试从后台服务项目中引用单例类时,单例类中的所有属性都是空的。
我已尝试检查单例类的 GetInstance 属性。从后台服务引用单例类时不会创建新实例,但属性仍然为空。
单例类:
public class UserTokenInfo
{
private static UserTokenInfo instance = null;
private static object lockThis = new object();
private UserTokenInfo() { }
public static UserTokenInfo GetInstance
{
get
{
lock (lockThis)
{
if (instance == null)
instance = new UserTokenInfo();
return instance;
}
}
}
public string access_token { get; set; }
public string expiry { get; set; }
public string Email { get; set; }
public bool isTokenValid()
{
if (Convert.ToDateTime(expiry) > DateTime.Now)
return true;
return false;
}
public string FirstName { get; set; }
public string SecondName { get; set; }
public List<string> Topic { get; set; } = new List<string>();
public List<string> Website { get; set; } = new List<string>();
}
【问题讨论】:
标签: c# windows-runtime singleton background-task