public void Enqueue() { using (var c = new PriorityQueueModel()) { string type = "Type" + StaticRandom.Next(1, 200); var tenant = (short) StaticRandom.Next(1, 10000); var principal = (short) StaticRandom.Next(1, 10000); var priority = (byte) StaticRandom.Next(1, 255); string payload = Guid.NewGuid().ToString(); c.usp_Enqueue(payload, type, tenant, principal, priority); } }
public void Dequeue() { using (var c = new PriorityQueueModel()) { using (var s = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { c.usp_Dequeue().FirstOrDefault(); // linq2sql gets angry if you don't open the reader //work s.Complete(); } } }
public ActionResult AddTask(FormCollection collection) { int prioridad = 0; setPriority(collection["Prioridad"]); PriorityQueueModel data = new PriorityQueueModel() { Priority = prioridad, Tarea = collection["Titulo"] }; if (!Storage.Instance.pendingDevelopersTasks.KeyExist(collection["Titulo"])) { Task nuevaTarea = new Task { Titulo = collection["Titulo"], Descripcion = collection["Descripcion"], Proyecto = collection["Proyecto"], Prioridad = collection["Prioridad"], Entrega = collection["Entrega"], UserName = Storage.Instance.currentUser.Username }; Storage.Instance.usersList.Find( (user) => { if (user.Username.CompareTo(Storage.Instance.currentUser.Username) == 0) { //Debug para ver si la data realmente se asigna... Storage.Instance.currentUser.Tasks.Insert(data.Priority, data.Tarea); Storage.Instance.pendingDevelopersTasks.Insert(nuevaTarea.Titulo, nuevaTarea); return(true); } else { return(false); } } ); } else { Response.Write("<script>alert('Esta tarea ya existe!')</script>"); return(View("AddTask")); } UpdateDB(); return(View("Menu")); }
public void DequeueWithTask() { Action a = () => { using (var c = new PriorityQueueModel()) { using ( var s = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted})) { c.usp_Dequeue().FirstOrDefault(); // linq2sql gets angry if you don't open the reader //work s.Complete(); } } }; Task taskA = new Task(a); Task taskB = new Task(a); var tasks = new List<Task> {taskA, taskB}; tasks.ForEach(t => t.Start()); Task.WaitAll(tasks.ToArray()); }