我进行了一个 ajax 调用,导致将大约 1000 行插入到 db 中,直到完成,ajax 调用挂起并等待响应。在 ajax 调用中,我调用我的 CreateNotification 方法。
实现这一点以防止 ajax 调用挂起的最佳方法是什么?
public static void CreateNewNotification(Guid UserGuid, string text, Guid questionGuid, string userName)
{
Notification notification;
LinqConnectionDataContext context = new LinqConnectionDataContext();
string baseUrl = text;
var listOfFolowers = Folower.getMyFolowers(UserGuid);
if (listOfFolowers.Count() != 0)
{
foreach (var item in listOfFolowers)
{
notification = new Notification();
notification.Url = baseUrl;
notification.UidCreationUser = UserGuid;
notification.UidFolowerUser = item.FolowerUserId;
notification.Text = userName + "just answered a question - " +text;
notification.Uid = Guid.NewGuid();
notification.CreationDate = DateTime.Now;
notification.Checked = false;
context.Notifications.InsertOnSubmit(notification);
}
}
try
{
context.SubmitChanges();
}
catch (Exception e)
{
}
}