public static void Kill(this WindowsAppFriend app)
        {
            if (app == null)
            {
                return;
            }

            app.ClearTimeout();
            try
            {
                Process.GetProcessById(app.ProcessId).Kill();
            }
            catch { }
        }
        public static void Clear()
        {
            if (_app == null)
            {
                return;
            }

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                End();
                return;
            }

            _app.ClearTimeout();
        }
        internal static void ResetTimeout(this WindowsAppFriend app)
        {
            app.ClearTimeout();

            var type   = _finder.GetType(TestContext.CurrentContext.Test.ClassName);
            var method = type.GetMethod(TestContext.CurrentContext.Test.MethodName);
            var attrs  = method.GetCustomAttributes(typeof(TimeoutExAttribute), true);

            if (attrs.Length == 1)
            {
                var timeout = (TimeoutExAttribute)attrs[0];
                var exe     = typeof(Killer.Program).Assembly.Location;
                _killer = Process.Start(exe, app.ProcessId + " " + timeout.Time + " \"" + TestResult.MakeErrPngPath() + "\"");
            }
        }
        internal static void ResetTimeout(this WindowsAppFriend app)
        {
            app.ClearTimeout();
            if (Debugger.IsAttached)
            {
                return;
            }

            var type   = _finder.GetType(TestContext.CurrentContext.Test.ClassName);
            var method = type.GetMethod(TestContext.CurrentContext.Test.MethodName);
            var attrs  = method.GetCustomAttributes(typeof(TimeoutExAttribute), true);

            if (attrs.Length != 1)
            {
                return;
            }

            var timeout = (TimeoutExAttribute)attrs[0];

            _alive  = true;
            _killer = new Thread(() => PollingTimeout(app, timeout));
            _killer.Start();
        }
        public static void TestCleanup()
        {
            if (_app == null)
            {
                return;
            }

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                var path = TestResult.MakeErrPngPath();

                //Killerが終了させた場合はすでにエラー画像が残っているので上書きしない
                if (!File.Exists(path))
                {
                    SaveFullScreeShot(path);
                }

                //終了させる
                _app.Kill();
                return;
            }

            //アプリがビジー状態になっているときも終了させる
            //終了操作に入って10秒で終了しないときはアプリがビジーとみなす
            bool alive = true;
            var  id    = _app.ProcessId;
            var  tsk   = Task.Factory.StartNew(() =>
            {
                var watch = new Stopwatch();
                watch.Start();
                while (alive)
                {
                    Thread.Sleep(1);
                }
                if (10000 < watch.ElapsedMilliseconds)
                {
                    try
                    {
                        Process.GetProcessById(id).Kill();
                    }
                    catch { }
                    try
                    {
                        var process = Process.GetProcessById(id);
                        if (process != null)
                        {
                            process.WaitForExit();
                        }
                    }
                    catch { }
                }
            });

            try
            {
                //何かモーダルウィンドウが残っていれば終了
                if (_app.GetFromTypeFullName("").Length != 1)
                {
                    _app.Kill();
                    _app = null;
                    return;
                }

                _app.Kill();
                _app = null;
            }
            catch
            {
                _app.Kill();
                _app = null;
            }
            finally
            {
                alive = false;
                tsk.Wait();
            }

            if (_app != null)
            {
                _app.ClearTimeout();
            }
        }