Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

GetProcessesByName causing windows XP to restart

$
0
0

Hi

I have developed an application which is use as console to run couple of other applications, on the startup the application checks if another of its module (.exe) is running or not, using “Process.GetProcessesByName()” method. And once the application is loaded it helps launching other 3rd party applications using Process.Start() method.

Recently, a new 3rd party application is introduced to my application. When my application tries to launch that new application, somehow the windows restarts (Windows XP).

I started debugging my application to dig out the issue, and found that “Process.GetProcessesByName()” method is causing the issue. Looking more into it, I found some memory leakage issue with the method.

I tried to avoid calling the method by using the following alternatives

Public Function GetProcessByName(ByVal ProcessName As String) As List(Of Process)

    Dim ls_Query As String
    Dim li_ProcessID As Integer
    Dim lObj_Process As New List(Of Process)
    Dim lObj_MSearcher As ManagementObjectSearcher
    Dim lObj_ProcessList As ManagementObjectCollection

    ls_Query = "Select * from Win32_Process Where Name = """ + ProcessName + """"
    '
    ' Initialize ManagementObjectSearcher
    '
    lObj_MSearcher = New ManagementObjectSearcher(ls_Query)
    '
    ' Get process list
    '
    lObj_ProcessList = lObj_MSearcher.Get()
    '
    ' Get process id
    '
    For Each lobj_Mprocess As ManagementObject In lObj_ProcessList
      li_ProcessID = Convert.ToInt32(lobj_Mprocess("ProcessId"))
      lObj_Process.Add(Process.GetProcessById(li_ProcessID))
    Next
    Return lObj_Process

  End Function

and the other is

 Public Function GetProcessByName(ByVal ProcessName As String) As List(Of Process)

    Dim lObj_Process As New List(Of Process)

    lObj_Process.Add(Process.GetProcesses().Where(Function(p) p.ProcessName = """ & ProcessName & """))

    Return lObj_Process

  End Function

But on launching the application, windows XP is restarting.

Can anyone help me in this regard?

Thanks & Regards,

Haroon.



Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>