Last post Apr 30, 2010 03:28 PM by atconway
Apr 29, 2010 12:58 PM|mark_bert|LINK
I have a web page that makes a call to an external DLL. The called function sends a request to another server that does a pretty time consuming database call and emails the results.
What I'd like to do is call the function and then just continue on with the processing of the page without waiting for the function to complete. As it stands now, the page waits until the function has completely finished before loading the rest of the page.
I want to be able to call the function and then forget about.
Any ideas are appreciated.
Apr 29, 2010 01:19 PM|Das.Sandeep|LINK
You can acheive this by multi threading or async call
Apr 30, 2010 07:51 AM|TATWORTH|LINK
You can run the DLL from a Windows Service.
The sequence is:
For an example of the code to produce this, please see
Apr 30, 2010 03:28 PM|atconway|LINK
Yes this is quite easy to do with a Asyncronous Delegate call. It will behave like a 'fire and forget' call and should behave exaclty as you are requesting. I do this at times when sending emails, and I do not want to wait for the email service to respond.
You can wire up a callback method if needed but in your case, you would just invoke the delegate (via
BeginInvoke) and continue processing. It takes very little code, and works well especially for Sub() or void functions that do not return any values.
Read the following closely and by the end of the article you should understand how to implement this in your code. You should concentrate on the code example in the 'Test Method and Asynchronous Delegate' and 'Waiting for an Asynchronous Call with EndInvoke'
sections. However your code will call the .BeginInvoke method passing the delegate and then you will be done. No need to use the .EndInvoke if you are not expecting any values back or need a callback method.
Asynchronous Programming Overview:
Private Delegate Sub DoSomethingDelegate(ByVal MyValue1 As String)
Dim AsyncResult As IAsyncResult
'Create an instance of the delegate with an address of the DoSomething() Sub
Dim Invoker As New DoSomethingDelegate(AddressOf DoSomething)
'Some random string to pass into method
Dim MyVal As String = "Hello"
'Invoke the delegate asynchronously and pass in the required parameters
AsyncResult = Invoker.BeginInvoke(MyVal, Nothing, Nothing)
'The Sub being called
Public Sub DoSomething(ByVal ImportantValue As String)
'Code goes here...
Hope this helps!