"Sunny" <su***@newsgrou ps.nospam> wrote in message
news:Oc******** ******@tk2msftn gp13.phx.gbl...
Hi Jon,
can you post a complete working sample. I can not see any problem here. Sunny
Here is the complete code. The problem is in the CreateCheckPCLD elegate
function. When the event is thrown the callback
is reentered over and over again, up to about 4 times before the error
message appears.
'************** *************** *************** *************** *************** *
*************** *************** ************
Class CheckPrintDeleg ate
Private Const CHECKPRINT_SERV ER As String =
"http://localhost/PrintServices/CheckPrintServi cesFBOD.rem"
Delegate Function CreateCheckPCLD elegate(ByRef CheckID As String, ByVal
XOffSet As Integer, ByVal YOffSet As Integer, ByRef PCLStream As Byte(),
ByRef ErrorMessage As String) As Boolean
Private m_xOffSet As Integer
Private m_yOffset As Integer
Private m_sRemoteURL As String
Private m_checkList As New CheckQueueList
Public Event CheckReceived(B yVal CheckID As String)
Private Sub New()
End Sub
Public Sub New(ByVal sRemoteURL As String)
Dim properties As New Hashtable
properties("nam e") = "HttpBinary "
m_sRemoteURL = sRemoteURL
Try
ChannelServices .RegisterChanne l(New HttpChannel(pro perties, New
BinaryClientFor matterSinkProvi der, Nothing))
' The last parameter above (Nothing) is the server sink provider
chain
' to obtain the default behavior (which includes SOAP and
' binary formatters on the server side).
Catch er As System.Runtime. Remoting.Remoti ngException
If er.Message.Inde xOf("already registered") < 0 Then
Throw New ApplicationExce ption(er.Messag e)
End If
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Sub
Public Property XOffset() As Integer
Get
Return (m_xOffSet)
End Get
Set(ByVal Value As Integer)
m_xOffSet = Value
End Set
End Property
Public Property YOffset() As Integer
Get
Return (m_yOffset)
End Get
Set(ByVal Value As Integer)
m_yOffset = Value
End Set
End Property
Public Sub ClearList()
m_checkList.Cle ar()
End Sub
Public ReadOnly Property CheckList() As CheckQueueList
Get
CheckList = m_checkList
End Get
End Property
Public Function GetDeclineLette rTemplate(ByRef sData As Byte(), ByRef
ErrorMessage As String) As Boolean
Dim objCheckPrintSe rvices As LTSWebChecks.Ch eckPrintService sFBOD
Dim bStatus As Boolean
Dim sStream As String
Try
objCheckPrintSe rvices =
CType(Activator .GetObject(GetT ype(LTSWebCheck s.CheckPrintSer vicesFBOD),
m_sRemoteURL), LTSWebChecks.Ch eckPrintService sFBOD)
bStatus = objCheckPrintSe rvices.GetDecli neLetterTemplat e(sData,
ErrorMessage)
Catch ex As Exception
Debug.Write(ex. Message)
Throw New ApplicationExce ption("GetDecli neLetterTemplat e():" &
ex.Message)
End Try
GetDeclineLette rTemplate = bStatus
End Function
Private Sub CreateCheckPCLC allback(ByVal result As IAsyncResult)
Dim objResult As AsyncResult = CType(result, AsyncResult)
Debug.WriteLine ("AsyncResul t = " & objResult.IsCom pleted.ToString )
Dim objDelegate As CreateCheckPCLD elegate = _
CType(objResult .AsyncDelegate, CreateCheckPCLD elegate)
Dim bStatus As Boolean
Dim sPCLData As Byte()
Dim sCheckID As String
Dim sErrorMsg As String
bStatus = objDelegate.End Invoke(sCheckID , sPCLData, sErrorMsg,
result)
m_checkList.Ite m(sCheckID).PCL Stream = sPCLData
m_checkList.Ite m(sCheckID).Com pleted = True
m_checkList.Ite m(sCheckID).Err ors = sErrorMsg
objDelegate = Nothing
RaiseEvent CheckReceived(s CheckID) '<<<========= Problem
is Here
Debug.WriteLine ("Result is <{0}>", bStatus.ToStrin g)
End Sub
Public Function GetMICRFont(ByR ef sPCLStream As Byte()) As Boolean
Dim objCheckPrintSe rvices As LTSWebChecks.Ch eckPrintService sFBOD
Dim bStatus As Boolean
Try
objCheckPrintSe rvices =
CType(Activator .GetObject(GetT ype(LTSWebCheck s.CheckPrintSer vicesFBOD),
m_sRemoteURL), LTSWebChecks.Ch eckPrintService sFBOD)
bStatus =
objCheckPrintSe rvices.CreateMI CRFontPCLStream (sPCLStream)
Catch ex As Exception
Debug.Write(ex. Message)
Throw New ApplicationExce ption("GetMICRF ont():" & ex.Message)
End Try
GetMICRFont = bStatus
End Function
Public Function GetTestPCLStrea m(ByVal CheckID As String, ByRef
sPCLStream As Byte(), ByRef sErrorMessage As String) As Boolean
Dim objCheckPrintSe rvices As LTSWebChecks.Ch eckPrintService sFBOD
Dim bStatus As Boolean
Try
objCheckPrintSe rvices =
CType(Activator .GetObject(GetT ype(LTSWebCheck s.CheckPrintSer vicesFBOD),
m_sRemoteURL), LTSWebChecks.Ch eckPrintService sFBOD)
bStatus =
objCheckPrintSe rvices.CreateTe stCheckPCLStrea m(CheckID, m_xOffSet,
m_yOffset, sPCLStream, sErrorMessage)
Catch ex As Exception
Debug.Write(ex. Message)
Throw New ApplicationExce ption("GetTestP CLStream():" &
ex.Message)
End Try
GetTestPCLStrea m = bStatus
End Function
Public Function GetPCLStream(By Val CheckID As String, ByRef sPCLStream
As Byte(), ByRef sErrorMessage As String) As Boolean
Dim objCheckPrintSe rvices As LTSWebChecks.Ch eckPrintService sFBOD
Dim bStatus As Boolean
Try
objCheckPrintSe rvices =
CType(Activator .GetObject(GetT ype(LTSWebCheck s.CheckPrintSer vicesFBOD),
m_sRemoteURL), LTSWebChecks.Ch eckPrintService sFBOD)
bStatus = objCheckPrintSe rvices.CreateCh eckPCLStream(Ch eckID,
m_xOffSet, m_yOffset, sPCLStream, sErrorMessage)
Catch ex As Exception
Debug.Write(ex. Message)
Throw New ApplicationExce ption("GetPCLSt ream():" & ex.Message)
End Try
Return (bStatus)
End Function
Public Sub QueuePCLStream( ByVal CheckID As String)
Dim objCallback As New AsyncCallback(A ddressOf
CreateCheckPCLC allback)
Dim objCheckPrintSe rvices As LTSWebChecks.Ch eckPrintService sFBOD
Dim result As IAsyncResult
Dim sPCLStream As Byte()
Dim sErrorMsg As String
Try
objCheckPrintSe rvices =
CType(Activator .GetObject(GetT ype(LTSWebCheck s.CheckPrintSer vicesFBOD),
m_sRemoteURL), LTSWebChecks.Ch eckPrintService sFBOD)
Dim objDelegate As New CreateCheckPCLD elegate( _
AddressOf objCheckPrintSe rvices.CreateTe stCheckPCLStrea m)
'For Debuggin, Change from Test
m_checkList.Add (CheckID, Nothing, Nothing, False)
result = objDelegate.Beg inInvoke(CheckI D, m_xOffSet, m_yOffset,
sPCLStream, sErrorMsg, objCallback, _
Nothing)
'm_checkList.Ad d(CheckID, Nothing, Nothing, False)
Catch ex As Exception
Debug.Write(ex. Message)
Throw New ApplicationExce ption("QueuePCL Stream():" & ex.Message)
End Try
End Sub
Public Function GetQueuedCheckD ata(ByVal checkID As String) As
CheckQueueItem
'Note: This is a Volatile Get Function. It will return the
CheckQueueItem
' and then remove it from the list
GetQueuedCheckD ata = m_checkList.Ite m(checkID)
m_checkList.Rem ove(checkID)
End Function
End Class