Beispiel #1
0
        static void CheckForDeadlocks(object arg)
        {
            lock (executing)
            {
                bool newSuspects = false;
                List <AmnesiaDbCommand> suspects = null;

                foreach (var cmd in executing)
                {
                    if ((DateTime.Now - cmd.executionStartTime).TotalMilliseconds > DEADLOCK_WARNING_MS && !cmd.deadlockSuspected)
                    {
                        if (!cmd.deadlockSuspected)
                        {
                            cmd.deadlockSuspected = true;
                            newSuspects           = true;
                        }

                        if (suspects == null)
                        {
                            suspects = new List <AmnesiaDbCommand>();
                        }

                        suspects.Add(cmd);
                    }
                }

                if (newSuspects)
                {
                    for (int i = 0; i < suspects.Count; ++i)
                    {
                        AmnesiaDbCommand cmd = suspects[i];

                        if (i == 0)
                        {
                            Session.AsyncLog.Write("These commands have been executing for a long time and may be deadlocked:");
                        }

                        Session.AsyncLog.Write("#{2} [+{0}ms] {1}", (DateTime.Now - cmd.executionStartTime).TotalMilliseconds, cmd.CommandText, i + 1);
                        Session.AsyncLog.Write(new StackTrace(cmd.executingThread, true).ToString());
                    }
                }
            }
        }