By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

Delegates

P: n/a
Hi All

i m building up a windows service and want to call a function of a class in
a async mode

But i m confused that i m using it in a correct way or not. Here is the
class if i wrong then plz correct me.
Public Class DependencyChecker

Delegate Function AsyncDependencyCheck(ByVal JobID As Long) As Integer

Public Function BeginDependencyCheck(ByVal JobID As Long, ByVal callback
As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Dim cd As AsyncDependencyCheck = AddressOf DependencyCheck
Dim result As IAsyncResult = cd.BeginInvoke(JobID, callback,
asyncState)
Return result
End Function

Public Function EndDependencyCheck(ByVal Result As System.IAsyncResult)
As Integer
Dim cd As AsyncDependencyCheck = CType(CType(Result,
AsyncResult).AsyncDelegate, AsyncDependencyCheck)
Dim o As Object = cd.EndInvoke(Result)
Return CType(o, String)
End Function

Public Function DependencyCheck(ByVal JobID As Long) As Integer
'Do my work and return JOBID
return jobid
end function

End class
and this is how i call it.

Private Sub TmrAll_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles TmrAll.Elapsed
Call DependencyChecker()
End Sub

Sub DependencyChecker()
'Get the jobid from database
Dim WsDependency As DependencyChecker = New DependencyChecker
Dim result As IAsyncResult =
WsDependency.BeginDependencyCheck(CInt(JobsDataCon tainer.Fields("Jobid")),
AddressOf DependencyCheckCallBack, WsDependency)
WsDependency = Nothing

end sub

Private Sub DependencyCheckCallBack(ByVal Result As IAsyncResult)
Dim WsDependencyChecker As DependencyChecker = CType(Result.AsyncState,
DependencyChecker)
Jobid = WsDependencyChecker.EndDependencyCheck(Result)
'and now process the jobid to delete it from the current que.
end sub

and i set the WsDependency to nothing as this will be called many times in
the timer control.

Is the above method correct in vb???

Cheers
Chintan
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.