﻿Imports System.Threading

Partial Class _Default
    Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i, nPasses As Integer
        nPasses = TextBox1.Text
        For i = 1 To nPasses
            ThreadPool.QueueUserWorkItem(AddressOf Go, i)
        Next
End Sub

Shared Sub Go(ByVal stateInfo As Object)

        Dim env As IntPtr
        Dim lng As New Lingo
        env = Lingo.LScreateEnvLng()
        If (env = 0) Then
            MsgBox("Unable to create Lingo environment.")
            Exit Sub
        End If

        Dim cLog As String
        cLog = "\lingo64_18\lingo" & stateInfo.ToString & ".log"
        Lingo.LSopenLogFileLng(env, cLog)

        Dim cScript As String

        cScript = "take \lingo64_18\tran.ltf" & Chr(10)
        cScript = cScript + "quit" + Chr(10)

        Dim nErr As Integer
        nErr = Lingo.LSexecuteScriptLng(env, cScript)
        If (nErr <> 0) Then
            MsgBox("Error running script.")
            Exit Sub
        End If

        Lingo.LScloseLogFileLng(env)

        Lingo.LSdeleteEnvLng(env)

    End Sub

End Class