Beispiel #1
0
        public static void AsyncTaskStatus_FillRow(object o, out SqlInt16 SessionID, out SqlString Status, out SqlString Command, out SqlString Error, out SqlDateTime EnqueueDate, out SqlDateTime ExecutionStartDate, out SqlDateTime ExecutionEndDate)
        {
            AsyncTaskItem item = (AsyncTaskItem)o;

            SessionID          = new SqlInt16(item.SPID);
            Status             = new SqlString(item.Status);
            Command            = new SqlString(item.Command.CommandText);
            Error              = item.Error == null ? SqlString.Null : new SqlString(item.Error.ToString());
            EnqueueDate        = new SqlDateTime(item.EnqueueDate);
            ExecutionStartDate = item.ExecutionStartDate == DateTime.MaxValue ? SqlDateTime.Null : new SqlDateTime(item.ExecutionStartDate);
            ExecutionEndDate   = item.EndDate == DateTime.MaxValue ? SqlDateTime.Null : new SqlDateTime(item.EndDate);
        }
Beispiel #2
0
 void SetItemStatus(AsyncTaskItem item, string status)
 {
     item.Status = status;
     if (status == "Running")
     {
         item.ExecutionStartDate = DateTime.Now;
     }
     else
     {
         item.EndDate = DateTime.Now;
     }
 }
Beispiel #3
0
        void RunOne()
        {
            AsyncTaskItem item = null;

            try
            {
                lock (syncObj)
                {
                    if (waitingList.Count == 0)
                    {
                        return;
                    }
                    item = waitingList[0];
                    runningList.Add(item);
                    waitingList.Remove(item);
                }
                SetItemStatus(item, "Running");
                using (SqlConnection connection = new SqlConnection(connectionStringPooled))
                {
                    item.Command.Connection = connection;
                    if (IsClosed)
                    {
                        SetItemStatus(item, "Aborted");
                    }
                    connection.Open();
                    item.SPID = GetSessionID(connection);
                    if (IsClosed)
                    {
                        SetItemStatus(item, "Aborted");
                        return;
                    }

                    item.Command.ExecuteNonQuery();
                    SetItemStatus(item, "Finished");
                }
            }
            catch (Exception e)
            {
                item.EndDate = DateTime.Now;
                if (e is SqlException)
                {
                    if (((SqlException)e).Number == 0)
                    {
                        //either session is killed or SQL Command is cancelled.
                        SetItemStatus(item, "Cancelled");

                        //Error = e;
                        //if (IsClosed)
                        //    SetItemStatus(item, "Cancelled");
                        //else
                        //    SetItemStatus(item, "Finished");
                        return;
                    }
                }
                SetItemStatus(item, "Error");
                Error      = e;
                item.Error = e;
            }
            finally
            {
                lock (syncObj)
                {
                    runningThreads--;
                    if (item != null)
                    {
                        runningList.Remove(item);
                        completeList.Add(item);
                    }
                }
            }
        }