VB.NET:
#Region "Imports"
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Text
Imports System.Net.Sockets
#End Region
Public Class TestBGWorker
Dim Threadreceive As Thread
Protected Sub OnStart(ByVal args() As String)
Try
Threadreceive = New Thread(AddressOf CommandReceiver.Receive_Data)
Threadreceive.Start()
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub
End Class
Public Class CommandReceiver
Dim mainLoopthread As Thread
Private Sub start()
Try
mainLoopthread = New Thread(AddressOf Receive_Data)
mainLoopthread.Name = "MainLoop"
mainLoopthread.IsBackground = True
mainLoopthread.Start()
Catch ex As Exception
MsgBox("START Exception:" + ex.Message + ":" + ex.StackTrace)
End Try
End Sub
Private Sub StopService()
Try
mainLoopthread.Join()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Shared Sub Receive_Data()
Try
Dim ex As Socket
Dim ar As IAsyncResult = _
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This is line 46
'Im getting this error
'C:\Inetpub\wwwroot\DBWeb\AppCommServiceNew\TestBGWorker.vb(46):
'Cannot refer to an instance member of a class from within a shared
'method or shared member initializer without an explicit instance of the
'class.
'It puts the squigly lines on the onMessage arrival...Can anyone help me
'Please......Thanks in advance
ex.BeginReceive(New TimeSpan(1, 0, 0, 0), ex, New AsyncCallback(AddressOf OnMessageArrival))
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Catch e As Messaging.MessageQueueException
MsgBox("Message could not be received from the MessageQueue: " + e.Message)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Friend Sub OnMessageArrival(ByVal ar As IAsyncResult)
Dim mq As Messaging.MessageQueue = ar.AsyncState
Try
Dim message As New Messaging.Message()
message = mq.EndReceive(ar)
Catch ex As Exception
If ex.Message.IndexOf("Timeout") > -1 Then
Else
MsgBox("Listener Exception:" + ex.Message + ": " + ex.StackTrace)
End If
Finally
mq.BeginReceive(TimeSpan.FromSeconds(5), mq, New AsyncCallback(AddressOf OnMessageArrival))
End Try
End Sub
Private Function GetDbInfo(ByVal num As Integer, ByVal sndInfo As String) As String
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Server=IMCWP1;Database=ApComm;User ID=webuser;Password=gr8data"
oSQLConn.Open()
Dim cmd As System.Data.SqlClient.SqlCommand = oSQLConn.CreateCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "usp_s_students"
cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int)).Value = num
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader
dr.Read()
Return dr(sndInfo)
End Function
End Class
Last edited by a moderator: