Solved

visual basic sleep issue

Posted on 2007-03-28
3
259 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 65
Passing a Text Box name to a Sub 6 104
Added a column screws up code 5 78
how to Classify of email (pdf attachments) 7 57
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

751 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