Ejemplo n.º 1
0
        public static Win32API.SYSTEM_HANDLE_INFORMATION[] FindHandles(string filesearchstring)
        {
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
            List <Win32API.SYSTEM_HANDLE_INFORMATION> lstHandles = new List <Win32API.SYSTEM_HANDLE_INFORMATION>();
            List <ManualResetEvent>        doneEvents            = new List <ManualResetEvent>();
            List <ProcessFileHandleFinder> processfinders        = new List <ProcessFileHandleFinder>();

            int i = 0;

            foreach (System.Diagnostics.Process proc in processes)
            {
                ManualResetEvent event_reset = new ManualResetEvent(false);
                doneEvents.Add(event_reset);
                ProcessFileHandleFinder prc_handler = new ProcessFileHandleFinder(proc, event_reset, filesearchstring);
                processfinders.Add(prc_handler);


                ThreadPool.QueueUserWorkItem(prc_handler.FindFileHandlesThreadPoolCallback, i);
                i++;

                if (i > 61)
                {
                    WaitHandle.WaitAll(doneEvents.ToArray());
                    foreach (ProcessFileHandleFinder prc in processfinders)
                    {
                        lstHandles.AddRange(prc.Handles.ToArray());
                    }
                    processfinders.Clear();
                    processfinders = new List <ProcessFileHandleFinder>();
                    i = 0;
                    doneEvents.Clear();
                    doneEvents = new List <ManualResetEvent>();
                }
            }


            WaitHandle.WaitAll(doneEvents.ToArray(), 60000);

            foreach (ProcessFileHandleFinder prc in processfinders)
            {
                if (prc.Handles != null && prc.Handles.Count > 0)
                {
                    lstHandles.AddRange(prc.Handles.ToArray());
                }
            }

            return(lstHandles.ToArray());
        }
Ejemplo n.º 2
0
        public static Win32API.SYSTEM_HANDLE_INFORMATION[] FindHandles(string filesearchstring)
        {
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
            List<Win32API.SYSTEM_HANDLE_INFORMATION> lstHandles = new List<Win32API.SYSTEM_HANDLE_INFORMATION>();
            List<ManualResetEvent> doneEvents = new List<ManualResetEvent>();
            List<ProcessFileHandleFinder> processfinders = new List<ProcessFileHandleFinder>();

            int i = 0;
            foreach (System.Diagnostics.Process proc in processes)
            {

                ManualResetEvent event_reset = new ManualResetEvent(false);
                doneEvents.Add(event_reset);
                ProcessFileHandleFinder prc_handler = new ProcessFileHandleFinder(proc, event_reset, filesearchstring);
                processfinders.Add(prc_handler);

                ThreadPool.QueueUserWorkItem(prc_handler.FindFileHandlesThreadPoolCallback, i);
                i++;

                if (i > 61)
                {
                    WaitHandle.WaitAll(doneEvents.ToArray());
                    foreach (ProcessFileHandleFinder prc in processfinders)
                    {
                        lstHandles.AddRange(prc.Handles.ToArray());
                    }
                    processfinders.Clear();
                    processfinders = new List<ProcessFileHandleFinder>();
                    i = 0;
                    doneEvents.Clear();
                    doneEvents = new List<ManualResetEvent>();
                }
            }

            WaitHandle.WaitAll(doneEvents.ToArray(), 60000);

            foreach (ProcessFileHandleFinder prc in processfinders)
            {
                if (prc.Handles != null && prc.Handles.Count > 0)
                {
                    lstHandles.AddRange(prc.Handles.ToArray());
                }
            }

            return lstHandles.ToArray();
        }