/// <summary> /// This will execute the specified query on a background thread - i.e. caller does not need to wait for it to finish /// </summary> /// <param name="db"></param> /// <param name="sqlString"></param> /// <param name="timeout"></param> /// <param name="parameters"></param> /// <remarks></remarks> public void ExecuteNonQueryAndForget(Database db, string sqlString, int timeout, params DbParameter[] parameters) { ExecuteNonQueryAndForgetWrapper taskParams = new ExecuteNonQueryAndForgetWrapper() { Db = db, SqlString = sqlString, Timeout = timeout, Parameters = parameters, Context = HttpContext.Current }; ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteNonQueryAndForgetCallback), taskParams); }
private void ExecuteNonQueryAndForgetCallback(object stateInfo) { ExecuteNonQueryAndForgetWrapper wrapper = stateInfo as ExecuteNonQueryAndForgetWrapper; if (HttpContext.Current == null && wrapper.Context != null) { HttpContext.Current = wrapper.Context; } try { ExecuteNonQuery(wrapper.Db, wrapper.SqlString, wrapper.Timeout, wrapper.Parameters); } catch (Exception) { // ignore } }