mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-09 23:05:02 +03:00
Fix async (#10218)
* Fix async * Fix async for statistics * Try fix pac async * Fix
This commit is contained in:
@@ -22,7 +22,7 @@ public class HttpClientHelper
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<string?> TryGetAsync(string url)
|
||||
public async Task<string?> TryGetAsync(string url, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
@@ -31,8 +31,12 @@ public class HttpClientHelper
|
||||
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetAsync(url);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
var response = await httpClient.GetAsync(url, cancellationToken);
|
||||
return await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -75,15 +75,28 @@ public sealed class SQLiteHelper
|
||||
|
||||
public async Task DisposeDbConnectionAsync()
|
||||
{
|
||||
await Task.Factory.StartNew(() =>
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_db?.Close();
|
||||
_db?.Dispose();
|
||||
_db = null;
|
||||
try
|
||||
{
|
||||
_db?.Close();
|
||||
_db?.Dispose();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_db = null;
|
||||
}
|
||||
|
||||
_dbAsync?.GetConnection()?.Close();
|
||||
_dbAsync?.GetConnection()?.Dispose();
|
||||
_dbAsync = null;
|
||||
try
|
||||
{
|
||||
var conn = _dbAsync?.GetConnection();
|
||||
conn?.Close();
|
||||
conn?.Dispose();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbAsync = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user