Pausing a program to "interact" with user?

To all,

Just thinking about a possible option to a program and seeking advice. I have a program which loops through a user selection to create some results. The overall duration of the loop can be hours (last time was ~8.5hrs !). If running overnight not a big issue. While there are plenty of info being written in the LW to let the user know what is happening there is no way of stopping the program without “killing” the NX session. I am however thinking about the option of pausing the program, for a few seconds, at the end of each (main) loop to ask the user if he wants to carry on. Some web searches are pointing toward a StopWatch, see below, but as you may have guessed it, I need to interact with the user.

' Create a Stopwatch and sleep for zero milliseconds.
Dim mystopwatch As Stopwatch = mystopwatch.StartNew
Thread.Sleep(0)
mystopwatch.Stop()
' Write the current time.
theLW.WriteLine("elapse time 1" & mystopwatch.ElapsedMilliseconds)
theLW.WriteLine("date1 " & DateTime.Now.ToLongTimeString)

I am therefore playing with a simple function but as suspected it does not work because the Messagebox stays displayed until Yes/No is pressed. I need the messagebox to appears and automatically disappear (answer = no) after say 5 seconds

Is there a way of tackling such problem without a Windows form?

Function PauseLoop() As Boolean
Dim StartTime, EndTime As Date
Dim dElapseTime As Double = 0
PauseLoop = False

StartTime = Now
While dElapsetime < 5
EndTime = Now
dElapseTime = EndTime.Subtract(StartTime).TotalSeconds
'Answer = 1 = Yes Answer = 2 = No
Dim answer, title, question As String
title = "the title"
question = "Carry on with next loop?"
answer = theUISession.NXMessageBox.Show(title, NXMessageBox.DialogType.Question, question )

If answer = 1 Then
PauseLoop = True
Exit While
End if

End While

End Function

If the NX API were more multi-threading friendly, this would be a good use case. One or more threads could do the work while one displays a cancel button to the user; if/when the cancel button is pressed that thread would interrupt the others and stop the operation. Unfortunately, I'm not currently aware of any API function that will do what you want; and since multithreading isn't an option, I don't think a windows form would help here either.

I do have one suggestion though; you could open a second session of NX and get some work done while the first session cranks away on your code. Just don't open/modify the same files that the first session is using!

Thanks for the input. I have seen stuff on "multithreading" but at this moment in time it is beyond my programming skills (and most likely will always be!)

Looks Like I'll have to ditch the idea. I have used a second NX session while the program is running. The trick is to run it overnight!

Thanks again

Thanks
Regards

Did more search out of (intellectual) interest and came across the Popup Method
https://technet.microsoft.com/en-us/library/ee156593.aspx
https://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx

So I wrote a simple test case , see code below, which works if timeout = 2 any other value and the msg box stays!
Has anyone get experience with this method?

#Region "Import Options"
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Collections.Generic
Imports System.Threading
Imports System.Array
Imports System.Globalization
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports System.Windows.Forms
Imports NXOpen.BlockStyler
#End Region

Module test

Public Dim theSession As Session = Session.GetSession()

Sub Main ()

Dim theLW As ListingWindow = theSession.ListingWindow

theLW.Open()
theLW.WriteLine ("-----------------------------------")

Const wshYes As Integer = 6
Const wshNo As Integer = 7
Const wshYesNoDialog As Integer = 4
Const wshQuestionMark As Integer = 32

Dim TimeoutValue As Integer = 2

Dim stitle As String = "Carry on request"
Dim smsg As String = "Do you want to carry on?"

Dim objShell As Object

objShell = CreateObject("Wscript.Shell")

Dim ireturn As Integer
ireturn = objShell.Popup(smsg, TimeoutValue, stitle, wshYesNoDialog + wshQuestionMark + 4096)

If ireturn = wshYes Then
theLW.WriteLine("you want to carry on")
ElseIf ireturn = wshNo Then
theLW.WriteLine("You want to stop")
Else
theLW.WriteLine("The popup timed out so let's carry on")
End If
End Sub
End Module

Thanks
Regards