I’m trying to fire off a WCF service call in a 100% asynchronous manner using the System.Threading.Tasks library. When I call the HandleChange method in the code example below, it seems to still wait until the client service call is complete before moving on past the line. I would like to do something like this, but not “hold up the show” – meaning I want the method calling this to just move onto the next line of code before the client call is complete. I may be just approaching this incorrectly, so if anyone can provide insight on what I’m doing wrong, or how I can achieve what I’m going for here, I would greatly appreciate it.
Imports System.Threading.Tasks
Public Class ChangeWrapper
Public Shared Sub HandleChange(ByVal orgEntity As MainObjectBase, ByVal newEntity As MainObjectBase)
Parallel.Invoke(Sub()
Using client As New EventQueueService.EventQueueClient
client.QueueDecision(orgEntity, newEntity)
End Using
End Sub)
End Sub
End Class
EDIT: To reflect what I changed based on SLaks Answer
Imports System.Threading.Tasks
Public Class ChangeWrapper
Public Shared Sub HandleChange(ByVal orgEntity As MainObjectBase, ByVal newEntity As MainObjectBase)
Task.Factory.StartNew(Sub()
Using client As New EventQueueService.EventQueueClient
client.QueueDecision(orgEntity, newEntity)
End Using
End Sub)
End Sub
End Class
The
Parallelclass is used to run things in parallel, but synchronously.To run something asynchronously, use the
Taskclass.You want
Task.Factory.StartNew().