ASP.NET Web Form

Sorry my English is bad I made script to force stop task for entity framework while getting result from query. Because my company using OpenEdge 2007 32-bit until now and have 1446 tables. When i run query from entity framework, i randomly get stuck and server cpu usage raise 100%. I made script dan manages all connection to database, so admin can terminate or when a timeout occurs the progress will stop. I made it with cancellion token and task.Dispose() buat when get randomly stuck, the server cpu still 100% while the current task has been terminated admin or timeout. Dispose and CancellionToken. But when i terminate the process server cpu drops to 0%. Then how can i terminate if get stuck while getting result from server? It doesn't get stuck forever, just stuck for a minute. This is sample code when i get records with entity framework.
var users = TaskUtils.QueryTask<User>(async _cancel => await context.Users.ToArrayAsync(_cancel), TimeSpan.FromMinutes(1));
var users = TaskUtils.QueryTask<User>(async _cancel => await context.Users.ToArrayAsync(_cancel), TimeSpan.FromMinutes(1));
This is code for TaskUtils.QueryTask
public static T[] QueryTask<T>(Func<CancellationToken, Task<T[]> Action, TimeSpan? Timeout = null, string TableName = null) where T : class
{
QueryTask task = QueryTask():
try{
task.CancelTokenSource = new CancellationTokenSource();
task.DateStarted = DateTime.Now;
task.Table = typeof(T);
task.TableName = TableName ?? DbUtils.GetTableName(typeof(T));
Task<T[]> cTask = Task.Run(async()=> await Action(task.CancelTokenSource));
task.WorkingTask = cTask;
RunningTasks.Add(task);
bool success = true;
if (Timeout != null) success = cTask.Wait(Timeout.Value);
RunningTasks.Remove(task);
if (!success){
cTask.Dispose();
}
return cTask.Result;
}catch{
//...
}
}
public static T[] QueryTask<T>(Func<CancellationToken, Task<T[]> Action, TimeSpan? Timeout = null, string TableName = null) where T : class
{
QueryTask task = QueryTask():
try{
task.CancelTokenSource = new CancellationTokenSource();
task.DateStarted = DateTime.Now;
task.Table = typeof(T);
task.TableName = TableName ?? DbUtils.GetTableName(typeof(T));
Task<T[]> cTask = Task.Run(async()=> await Action(task.CancelTokenSource));
task.WorkingTask = cTask;
RunningTasks.Add(task);
bool success = true;
if (Timeout != null) success = cTask.Wait(Timeout.Value);
RunningTasks.Remove(task);
if (!success){
cTask.Dispose();
}
return cTask.Result;
}catch{
//...
}
}
No description
No description
1 Reply
Roland Vincent
Roland VincentOP7mo ago
Sorry, i mean, when i stop debugging visual studio, the server cpu drop to zero.
Want results from more Discord servers?
Add your server