Solved

visual basic sleep issue

Posted on 2007-03-28
3
257 Views
Last Modified: 2013-12-26
Hello,

I've got a little issue with my visual basic application.  A part of my code reacts on an other way in Win2K then in WinXP.  Has anyone any idea how I resolve this?  It's a wait process.  When I start this in Win2K my wait process waits like it should when a process is ended it continues.  In WinXP it keeps sleeping and doesn't want to continue.  Here is the code I use:
Public Sub WaitForProcess(ByVal PID As Integer)

        Dim hProcess As Integer
        'Dim teller As Integer

        Do
            hProcess = OpenProcess(SYNCHRONIZE, 0, PID)
            MsgBox(hProcess.ToString)
            If hProcess <> 0 Then CloseHandle(hProcess)
            Sleep(100)
            System.Windows.Forms.Application.DoEvents()
        Loop While hProcess <> 0

    End Sub

I hope that someone can help me

thnx.
0
Comment
Question by:Pingolin
3 Comments
 
LVL 11

Expert Comment

by:Sven
ID: 18807085
The MsgBox has to be confirmed before the code will continue. VB will stop on a standard MsgBox independent on the operating system.
0
 

Author Comment

by:Pingolin
ID: 18807105
No, I've putted it there when I saw it was sleeping so I could check if my processnumber gets 0.  But it has to go to 0 but my process is still alive.  When I check my Task Manager I don't see my outlook process anymore.  And that is very strange.  My code works fine for Windows 2000 but not for Windows XP.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 18808571
It looks like you converted some VB6 code for use in VB.Net.

You can do this with managed .Net methods (no APIs):

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WaitForProcess(2948)
    End Sub

    Public Sub WaitForProcess(ByVal PID As Integer)
        Try
            Dim p As Process = Process.GetProcessById(PID)
            If Not (p Is Nothing) Then
                While Not p.HasExited
                    p.WaitForExit(100)
                    Application.DoEvents()
                End While
            End If
        Catch ex As Exception
            ' You get here if no process is running with the specified PID
        End Try
    End Sub
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question