Solved

visual basic sleep issue

Posted on 2007-03-28
3
254 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now