Solved

visual basic sleep issue

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 create a duplicate finder Application 9 127
Put text in a picture ASP.NET C# 2 68
Access query that references subform 5 48
message box in access 4 52
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

735 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