小编tec*_*030的帖子

另一个不等待的等待

通常我不会发帖,而是阅读并找到答案。

\n\n

但这一次,尽管我发现了十几篇关于异步/等待问题的帖子,但似乎没有解决方案适合我的情况(或者我至少不明白)。

\n\n

我的代码真的很长,所以我不会把它完整地放在这里,但它看起来像这样:\n我有一个正在数据库中写入的任务:

\n\n
public async Task WatchSpool(Button buttonSend)\n{\n    LoadOptions();\n    //SpoolWatcher spoolWatcher = new SpoolWatcher(this, buttonSend);\n    SpoolWatcher spoolWatcher = new SpoolWatcher(this);\n    spoolWatcher.OnSpoolWatcherException += OnSpoolWatcherException;\n    Task thread = new Task(spoolWatcher.Run);\n    spoolWatcherMustStop = false;\n    thread.Start();\n    //spoolWatcher.Run();\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后另一个计算数据库中特定表中的记录数:

\n\n
public int CountWaitingRecords(string table)\n{\n    int WaitingRecords = 0;\n    try\n    {\n        using (SqliteConnection connexion = new SqliteConnection("Filename = spool.db"))\n        {\n            connexion.Open();\n            using (SqliteCommand cmd = new SqliteCommand("SELECT COUNT(*) AS Count FROM " + table, connexion))\n            {\n                SqliteDataReader rs = cmd.ExecuteReader();\n                rs.Read();\n\n                WaitingRecords …
Run Code Online (Sandbox Code Playgroud)

c# task async-await uwp

0
推荐指数
1
解决办法
233
查看次数

标签 统计

async-await ×1

c# ×1

task ×1

uwp ×1