1

This is my page load code from where I'm calling the thread

Private Sub StartScreen_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Try
            TmHeartbeat.Stop()
            TmHeartbeat.Interval = 600000
            TmHeartbeat.Start()
            ResetVariables()
            FormLoadSetting(Me)
            SetButtonProperty(btnEnglish, "\Images\ButtonBgBig.png", GetFormLabel("Start Screen", "Common", "Button English"))
            SetButtonProperty(btnSpanish, "\Images\ButtonBgBig.png", GetFormLabel("Start Screen", "Common", "Button Spanish"))
            SetDisplayTimer(DGT, False, Me, 1800000)

            MediaElement1.Source = New Uri(GetPath("Images\EnglishVideo\" & GetFormLabel("Start Screen", "Common", "Video")))

            If GetFormLabel("Start Screen", "Common", "Audio") <> "" Then
                PlayAudio(APlay, GetFormLabel("Start Screen", "Common", "Audio"))
            End If
            Dim t As New Thread(AddressOf TakeScreenshot)
            t.Start(Me)
            Dim AudioPlay As New System.Media.SoundPlayer


        Catch ex As Exception
            AliLogFileEntry(TransactionType.ErrorOnForm, "Error In Function: StartScreen_Loaded: " & Me.Title & ", ErrorMessage: " & ex.Message)
        End Try
    End Sub

And this the method which is being called

Public Sub TakeScreenshot(ByVal FormName As Window)
        If OG.GetValue("TakeScreenshot") <> "0" Then
            Try
                Thread.Sleep(4000)
                AliLogFileEntry(TransactionType.System, "In Function: TakeScreenshot")
                Dim scale As Double = OG.GetValue("Screenshot_Scale") / 100
                Dim screenshot As Byte() = GetJpgImage(FormName, scale, 100)
                Dim dir As DirectoryInfo = New DirectoryInfo("Screenshots")
                If Not dir.Exists Then dir = Directory.CreateDirectory(dir.FullName)
                Dim path As String = AppDomain.CurrentDomain.BaseDirectory
                Dim fileStream As New IO.FileStream("Screenshots\" & FormName.Title & ".jpg", FileMode.Create, FileAccess.ReadWrite)
                Dim binaryWriter As New IO.BinaryWriter(fileStream)
                binaryWriter.Write(screenshot)
                binaryWriter.Close()
            Catch ex As Exception
                AliLogFileEntry(TransactionType.ErrorOnForm, "Error In Function: TakeScreenshot , ErrorMessage: " & ex.Message)
            End Try
        End If
    End Sub

When i debug the code. Neither the thread is created nor the function is called. My aim is to create a asynchronous threading function.

4

0 回答 0