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));


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{
//...
}
}
rn_image_picker_lib_temp_d6b357e9-a1a6-46a6-8c84-e5af468f7f0b.jpg
rn_image_picker_lib_temp_e02f6eca-74cf-46a0-a841-55e27546ac6e.jpg
Was this page helpful?