Solved

visual basic sleep issue

Posted on 2007-03-28
3
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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