Not getting process state

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ashutosh Bhawasinka

    Not getting process state

    Hi,
    I am starting a process and I need to monitor it (wait and check if its
    still responding).

    But, I it seems that the Process.HasExit ed or Process.Exited doesn't work.

    I just need to know if the process is running & responding.

    I am using

    void somefn(...)
    {
    if(...)
    {
    ProcessStartInf o psi = new ProcessStartInf o();
    psi.FileName = this.Path;
    psi.Arguments = this.CreateArgu ments();
    psi.ErrorDialog = false;
    psi.UseShellExe cute = true; //tried with false also
    Process p = Process.Start(p si);

    p.Exited += new EventHandler(Ex ited);
    while (p.HasExited)
    {
    Thread.Sleep(10 00);
    }
    }
    return Success;
    }

    void Exited(object sender, EventArgs e)
    {
    MessageBox.Show ("Done");
    }

    The execution never enters the while loop nor the Exited method is called.

    Any ideas???

    Regards,
    Ashutosh
  • Gilles Kohl [MVP]

    #2
    Re: Not getting process state

    On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
    <smbs-msdn@nospam.nos pamwrote:
    >Hi,
    >I am starting a process and I need to monitor it (wait and check if its
    >still responding).
    >
    >But, I it seems that the Process.HasExit ed or Process.Exited doesn't work.
    >
    >I just need to know if the process is running & responding.
    >
    >I am using
    >
    > void somefn(...)
    > {
    > if(...)
    {
    ProcessStartInf o psi = new ProcessStartInf o();
    psi.FileName = this.Path;
    psi.Arguments = this.CreateArgu ments();
    psi.ErrorDialog = false;
    psi.UseShellExe cute = true; //tried with false also
    Process p = Process.Start(p si);
    >
    p.Exited += new EventHandler(Ex ited);
    Hmm, try swapping the two lines above ...
    while (p.HasExited)
    Don't you mean while(!p.HasExi ted)?

    {
    Thread.Sleep(10 00);
    }
    }
    return Success;
    }
    >
    void Exited(object sender, EventArgs e)
    {
    MessageBox.Show ("Done");
    }
    >
    >The execution never enters the while loop nor the Exited method is called.
    >
    >Any ideas???
    See above ...

    Regards,
    Gilles.

    Comment

    • Ashutosh Bhawasinka

      #3
      Re: Not getting process state

      Hi,
      Thanks for pointing out the mistake....it's such a silly one :)

      Actually, I was more interested in the callback. Do, you have any clue
      on that??

      Regards,
      Ashutosh

      Gilles Kohl [MVP] wrote:.
      On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
      <smbs-msdn@nospam.nos pamwrote:
      >
      >Hi,
      >I am starting a process and I need to monitor it (wait and check if its
      >still responding).
      >>
      >But, I it seems that the Process.HasExit ed or Process.Exited doesn't work.
      >>
      >I just need to know if the process is running & responding.
      >>
      >I am using
      >>
      > void somefn(...)
      > {
      > if(...)
      > {
      > ProcessStartInf o psi = new ProcessStartInf o();
      > psi.FileName = this.Path;
      > psi.Arguments = this.CreateArgu ments();
      > psi.ErrorDialog = false;
      > psi.UseShellExe cute = true; //tried with false also
      > Process p = Process.Start(p si);
      >>
      > p.Exited += new EventHandler(Ex ited);
      >
      Hmm, try swapping the two lines above ...
      >
      > while (p.HasExited)
      >
      Don't you mean while(!p.HasExi ted)?
      >
      >
      > {
      > Thread.Sleep(10 00);
      > }
      > }
      > return Success;
      > }
      >>
      > void Exited(object sender, EventArgs e)
      > {
      > MessageBox.Show ("Done");
      > }
      >>
      >The execution never enters the while loop nor the Exited method is called.
      >>
      >Any ideas???
      >
      See above ...
      >
      Regards,
      Gilles.
      >

      Comment

      • parez

        #4
        Re: Not getting process state

        On May 14, 4:03 pm, Ashutosh Bhawasinka <smbs-m...@nospam.nos pam>
        wrote:
        Hi,
        Thanks for pointing out the mistake....it's such a silly one :)
        >
        Actually, I was more interested in the callback. Do, you have any clue
        on that??
        >
        Regards,
        Ashutosh
        >
        Gilles Kohl [MVP] wrote:.
        On Thu, 15 May 2008 00:19:55 +0530, Ashutosh Bhawasinka
        <smbs-m...@nospam.nos pamwrote:
        >
        Hi,
        I am starting a process and I need to monitor it (wait and check if its
        still responding).
        >
        But, I it seems that the Process.HasExit ed or Process.Exited doesn't work.
        >
        I just need to know if the process is running & responding.
        >
        I am using
        >
        void somefn(...)
        {
        if(...)
        {
        ProcessStartInf o psi = new ProcessStartInf o();
        psi.FileName = this.Path;
        psi.Arguments = this.CreateArgu ments();
        psi.ErrorDialog = false;
        psi.UseShellExe cute = true; //tried with false also
        Process p = Process.Start(p si);
        >
        p.Exited += new EventHandler(Ex ited);
        >
        Hmm, try swapping the two lines above ...
        >
        while (p.HasExited)
        >
        Don't you mean while(!p.HasExi ted)?
        >
        {
        Thread.Sleep(10 00);
        }
        }
        return Success;
        }
        >
        void Exited(object sender, EventArgs e)
        {
        MessageBox.Show ("Done");
        }
        >
        The execution never enters the while loop nor the Exited method is called.
        >
        Any ideas???
        >
        See above ...
        >
        Regards,
        Gilles.
        That mite fix your problem. GC was probably taking your object
        (process) since you were not waiting in that loop and that might be
        the reason why Exited never got called..

        Comment

        • Gilles Kohl [MVP]

          #5
          Re: Not getting process state

          >Thanks for pointing out the mistake....it's such a silly one :)
          >
          >Actually, I was more interested in the callback. Do, you have any clue
          >on that??
          Try adding

          p.EnableRaising Events = true;

          Regards,
          Gilles.

          Comment

          • Linda Liu[MSFT]

            #6
            Re: Not getting process state

            Thanks all who help on this issue!

            Hi Ashutosh,

            In summary, there're three problems in your sample code snippet.

            1. You should set the EnableRaisingEv ents property of the Process to true
            for the Process component to receive notification that the process has
            exited.

            2. You should subscribe the Exited event of the Process before call the
            Start method of the Process.

            3. Change the condition in the while statement to "!p.HasExit ed" within the
            "somefn" method.

            For more information about the Process's Exited event, please refer to the
            following MSDN document:
            https://msdn2.microsoft.com/en-us/li...process.exited.
            aspx

            Hope this helps.
            If you have anything unclear, please feel free to let me know.

            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

            ications.

            Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
            where an initial response from the community or a Microsoft Support
            Engineer within 1 business day is acceptable. Please note that each follow
            up response may take approximately 2 business days as the support
            professional working with you may need further investigation to reach the
            most efficient resolution. The offering is not appropriate for situations
            that require urgent, real-time or phone-based interactions or complex
            project analysis and dump analysis issues. Issues of this nature are best
            handled working with a dedicated Microsoft Support Engineer by contacting
            Microsoft Customer Support Services (CSS) at
            http://msdn.microsoft.com/subscripti...t/default.aspx.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.


            Comment

            • Ashutosh Bhawasinka

              #7
              Re: Not getting process state

              Thanks everyone for your help. The issue is resolved now.

              Looks like I was sleeping while writing that code :)

              Regards,
              Ashutosh

              Linda Liu[MSFT] wrote:
              Thanks all who help on this issue!
              >
              Hi Ashutosh,
              >
              In summary, there're three problems in your sample code snippet.
              >
              1. You should set the EnableRaisingEv ents property of the Process to true
              for the Process component to receive notification that the process has
              exited.
              >
              2. You should subscribe the Exited event of the Process before call the
              Start method of the Process.
              >
              3. Change the condition in the while statement to "!p.HasExit ed" within the
              "somefn" method.
              >
              For more information about the Process's Exited event, please refer to the
              following MSDN document:
              https://msdn2.microsoft.com/en-us/li...process.exited.
              aspx
              >
              Hope this helps.
              If you have anything unclear, please feel free to let me know.
              >
              Sincerely,
              Linda Liu
              Microsoft Online Community Support
              >
              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.
              >
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

              ications.
              >
              Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 1 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions or complex
              project analysis and dump analysis issues. Issues of this nature are best
              handled working with a dedicated Microsoft Support Engineer by contacting
              Microsoft Customer Support Services (CSS) at
              http://msdn.microsoft.com/subscripti...t/default.aspx.
              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no rights.
              >
              >

              Comment

              Working...