I have a simple program to read data from a touchscreen overEthernet using a custom DLL provided by the touchscreenmanufacturer, and I want to read this data using the threadpool.When I use the threadpool to complete the task(StartThreadButton_Click), I encounter the following errormessage when I close my application.
.NET-BroadcastEventWindow.1.0.5000.0.3: WindowsApplication1.exe -Application Error
The instruction at "0x6c3b5115" referenced memory at"0x00000004". The memory could not be "read".
Click on OK to terminate the program
When I run the sub-routine without using the threadpool(StartNormalButton_Click), I do not encounter this error messagewhen I close my application.
Is anyone familiar with this type of error, and can anyone make asuggestion?
The outline of my code is included below.
Regards,
Ryan
Public Class Form1
Inherits System.Windows.Forms.Form
Friend Class RefreshDataArgsConstruct
Public parent As Form1
End Class
' Declare the ThreadPool
Dim myThreadPool As ThreadPool
Private Sub StartThreadButton_Click(ByVal sender As Object,ByVal e As EventArgs) Handles StartThreadButton.Click
Dim dataArgs As New RefreshDataArgsConstruct
dataArgs.parent = Me
myThreadPool.QueueUserWorkItem(New WaitCallback(AddressOfRefreshData), dataArgs)
End Sub
Private Sub StartNormalButton_Click(ByVal sender As Object,ByVal e As EventArgs) Handles StartNormalButton.Click
Dim dataArgs As New RefreshDataArgsConstruct
dataArgs.parent = Me
RefreshData(dataArgs)
End Sub
Public Sub RefreshData(ByVal dataArgs As Object)
Dim myParent As Form1 = CType(dataArgs.parent, Form1)
Dim data As CtrlStnData =ReadData(myParent.IpAddress.Text)
myParent.DataSample.Text = "Success: " &data.success.ToString
End Sub
' Reading the data from the touchscreen
Private Function ReadData(ByVal ip As String) As CtrlStnData
' Create a return variable
Dim data As CtrlStnData
' Lock the communication semaphore
SyncLock doFunc
' Read data from the touchscreen (DLL calls)
err = HKEtn_Init(10000, 2, 2, 2)
HKEtn_Close()
End SyncLock
' 0 = Error Occurred in Ethernet Comms
If err = 0 Then
data.success = False : Return data
Else
data.success = True : Return data
End If
End Function
End Class
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>KI8wXJaaZUu6Ki3xWKcJWg==</Id>