rspec/rules/S4583/vbnet/rule.adoc

98 lines
2.6 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
BeginInvoke without callback
----
Public Delegate Function AsyncMethodCaller() As String
Public Class Sample
Public Sub DoSomething()
Dim Example As New AsyncExample()
Dim Caller As New AsyncMethodCaller(Example.SomeMethod)
' Initiate the asynchronous call.
Dim Result As IAsyncResult = Caller.BeginInvoke(Nothing, Nothing) ' Noncompliant - Not paired With EndInvoke
End Sub
End Class
----
BeginInvoke with callback
----
Public Delegate Function AsyncMethodCaller() As String
Public Class Sample
Public Sub DoSomething()
Dim Example As New AsyncExample()
Dim Caller As New AsyncMethodCaller(Example.SomeMethod)
' Initiate the asynchronous call.
Dim Result As IAsyncResult = Caller.BeginInvoke(New AsyncCallback(Sub(ar)
End Sub), Nothing) ' Noncompliant - Not paired With EndInvoke
End Sub
End Class
----
== Compliant Solution
BeginInvoke without callback
----
Public Delegate Function AsyncMethodCaller() As String
Public Class Sample
Public Function DoSomething() As String
Dim Example As New AsyncExample()
Dim Caller As New AsyncMethodCaller(Example.SomeMethod)
' Initiate the asynchronous call.
Dim Result As IAsyncResult = Caller.BeginInvoke(Nothing, Nothing)
' ...
Return Caller.EndInvoke(Result)
End Function
End Class
----
BeginInvoke with callback
----
Public Delegate Function AsyncMethodCaller() As String
Public Class Sample
Public Sub DoSomething()
Dim Example As New AsyncExample()
Dim Caller As New AsyncMethodCaller(Example.SomeMethod)
' Initiate the asynchronous call.
Dim Result As IAsyncResult = Caller.BeginInvoke(New AsyncCallback(Sub(ar)
' Call EndInvoke to retrieve the results.
Dim Ret As String = Caller.EndInvoke(ar)
' ...
End Sub), Nothing)
End Sub
End Class
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]