【发布时间】:2016-08-03 11:18:27
【问题描述】:
我正在尝试使用 SQLite 在我的应用程序中创建一个 Account 表,但应用程序在 CreateTableAsync 调用期间挂起而没有引发错误。
LocalDataContext.Instance.CreateTablesAsync(typeof(Account)).Wait();
var account = LocalDataContext.Instance.GetFirstOrDefaultAsync<Account>().Result;
因此,应用程序进入第一个调用,永远不会到达第二行。
这是CreateTablesAsync方法的代码:
/// <summary>
/// Creates the local database tables.
/// </summary>
public async Task CreateTablesAsync(params Type[] tableTypes)
{
await _connection.CreateTablesAsync(tableTypes);
}
挂起时输出的最后一行是Found as 'sqlite3_column_int'.
这是Account 模型:
public class Account
{
/// <summary>
/// Primary key for record.
/// </summary>
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
/// <summary>
/// Gets or sets the Client ID.
/// </summary>
public string ClientId { get; set; }
/// <summary>
/// Gets or sets the User ID.
/// </summary>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the user password.
/// </summary>
public int Password { get; set; }
}
有人知道为什么会这样吗?
【问题讨论】:
-
使用
Result而不是仅仅运行任务并使用await LocalDataContext.Instance.GetFirstOrDefaultAsync<Account>()很可能是死锁。您可以使用Task.Run创建表,然后像上面那样简单地等待来检索。 stackoverflow.com/questions/13140523/… -
如果你读过它,你犯了一个错误,你正在使用 Xamarin.. :) 使用 swift 并忘记 xamarin.. 相同的 API 但稳定且有效.. 看到 @987654332 令人难以置信@,
nuint等等。非常非常糟糕的代码库
标签: c# sqlite asynchronous xamarin xamarin.forms