Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pause APP

Posted on 2006-06-08
6
Medium Priority
?
287 Views
Last Modified: 2010-04-23
I am very new to development so please bear with me here.  

I have a form that loads upon running the app.  That form has text and images on it and upon loading calls a vbscript and runs it without any issues.  Now what I need to do is tell the form to stay open for 20 seconds then show a closeso button  the user can close the application.  20 seconds is plenty of time for the vbscript to finish running.

Any help would be greatly appreciated.

Todd
0
Comment
Question by:Todd Wedlake
[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
6 Comments
 
LVL 8

Expert Comment

by:doraiswamy
ID: 16866361
1) You would need to disable the close icon on the right hand top corner of the form.
2) Have a CLOSE button. Initially disable it.
3) Have a timer. Set the interval property to 20000, which would give 20 second delay.
4) When the timer event occurs, enable the CLOSE button.
5) In the clicked event of the CLOSE button, end the app

Hope this helps. If you have any specific question, do ask.
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16866556
Here's a bit of advice: Don't use a timer to perform this operation, rather monitor the process and then enable the close button when it has completed.

[code]

Public Class Form1

    Dim m_process As System.Diagnostics.Process

    Private Sub OnFormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim command As String = "C:\Windows\System32\prnjobs.vbs -l"
        m_process = New System.Diagnostics.Process()
        m_process.StartInfo.FileName = "prnjobs.vbs"
        m_process.StartInfo.Arguments = "-l"
        m_process.Start()

        Dim delay As Integer = 20 * 1000

        Me.CloseButton.Enabled = False
        Me.AbortButton.Enabled = False

        If m_process.WaitForExit(delay) Then
            Me.CloseButton.Enabled = True
        Else
            Me.AbortButton.Enabled = True
        End If

    End Sub

    Private Sub OnCloseButton(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub OnAbortButton(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbortButton.Click
        m_process.Kill()
        Me.Close()
    End Sub
End Class

[/code]

David


David
0
 
LVL 2

Author Comment

by:Todd Wedlake
ID: 16870235
David.  your code does the trick.  However, the process (vbscript) runs before the dialog box ever comes up.  Is there a way to make the dialog come up first, then run the script, then enable the close button.  and I'll add one more wish here.  :)
Is there a way to make the dialog come up, run the script, enable the close button, and if the user doesn't click the close button within say 30 seconds, to go ahead and close the dialog and end the app?


thanks
todd
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16870598
Here is my version...

(VB.Net 2005 - earlier versions have a Closing event instead of FormClosing)

Public Class Form1

    Private p As Process
    Private WithEvents tmr As New System.Windows.Forms.Timer()
    Private FormIsClosing As Boolean = False

    Private T As System.Threading.Thread
    Private Delegate Sub ProcessExited()

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' force the form to completely show before continuing
        Me.Show()
        Application.DoEvents()

        ' start up the vbs (hidden) and the monitor thread
        Dim vbs As String = "C:\Documents and Settings\Michael\My Documents\1 VB Code\2 VBScript Testing\Pause.vbs"
        p = New Process
        p.StartInfo.FileName = vbs
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.Start()

        If Not (p Is Nothing) Then
            T = New System.Threading.Thread(AddressOf Me.MonitorProcess)
            T.Start()
        End If

        ' start up the timer
        tmr.Interval = 30000 ' 30 seconds
        tmr.Start()
    End Sub

    Private Sub p_Exited()
        ' this is run if the vbs file exits by itself (or is forcefully closed)
        ' marshal the call from the monitor thread onto'
        ' the main UI thread via a Delegate and Invoke()
        If Me.InvokeRequired Then
            Me.Invoke(New ProcessExited(AddressOf p_Exited))
        Else
            Me.Close()
        End If
    End Sub

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

    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
        Me.Close()
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        FormIsClosing = True
        ' kill the vbs process if it is still running
        If Not (p Is Nothing) Then
            If Not p.HasExited Then
                p.Kill()
            End If
        End If
    End Sub

    Private Sub MonitorProcess()
        ' wait for the vbs to exit or the form to close
        If Not p.HasExited Then
            While (Not FormIsClosing) AndAlso (Not p.HasExited)
                System.Threading.Thread.Sleep(50)
            End While
        End If
        If Not FormIsClosing Then
            ' if the form isn't closing then close it
            Me.p_Exited()
        End If
    End Sub

End Class
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16873718
It looks like Idle_Mind has got your question covered!

David
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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

609 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