Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Asynchronous Fire-And-Forget Call

Reply
Thread Tools

Asynchronous Fire-And-Forget Call

 
 
Stephen Barrett
Guest
Posts: n/a
 
      04-11-2006
I have read many threads related to async fire and forget type calls, but
none have addressed my particular problem.

I have a webpage that instantiates a BL object and makes a method call. The
BL object method actually sets up a delegate and calls a private method
asynchronously and immediately returns back to the web page.

The problem I am having is that the async call never happens. I added a
quick logging call immediately as the first line of code in the method that
is suppose to get called asynchronously and it never gets called.

I am using an AsyncHelper class mentioned in other posts to help get around
the memory leak issues regarding not calling EndInvoke after a BeginInvoke.

If I call the public method of the BL and just have it call the internal one
without using an async delegate, everything works fine except that the
webpage eventually times out because it can be a very long process.

I am thinking about maybe spawning a new thread manually and letting handle
the long running process to see if I can around the issue. Any ideas on how
to do this asynchronously fire-and-forget within the BL would be greatly
appreciated.


 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      04-11-2006
You should probably set up a Windows Service to handle such background tasks
reliably.
In ASP.NET threads come and go too quickly for synchronization to be of much
use in most cases.

Here's more info on Windows Services:
http://msdn.microsoft.com/library/de...plications.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Stephen Barrett" <> wrote in message
news:...
>I have read many threads related to async fire and forget type calls, but
>none have addressed my particular problem.
>
> I have a webpage that instantiates a BL object and makes a method call.
> The BL object method actually sets up a delegate and calls a private
> method asynchronously and immediately returns back to the web page.
>
> The problem I am having is that the async call never happens. I added a
> quick logging call immediately as the first line of code in the method
> that is suppose to get called asynchronously and it never gets called.
>
> I am using an AsyncHelper class mentioned in other posts to help get
> around the memory leak issues regarding not calling EndInvoke after a
> BeginInvoke.
>
> If I call the public method of the BL and just have it call the internal
> one without using an async delegate, everything works fine except that the
> webpage eventually times out because it can be a very long process.
>
> I am thinking about maybe spawning a new thread manually and letting
> handle the long running process to see if I can around the issue. Any
> ideas on how to do this asynchronously fire-and-forget within the BL would
> be greatly appreciated.
>



 
Reply With Quote
 
 
 
 
Stephen Barrett
Guest
Posts: n/a
 
      04-11-2006
I would really love to go the service route. What I originally specd out
was for the BL that the webpage calls to write a message to MSMQ and have a
service that processed messages from the queue. This would be quick and not
involve extra threading and such.

Unfortunately, things out of my control prevent me from using any form of
windows service. The app is deployed to a shared server that many other app
groups use and the high-level managers on the IT side have limited us on
what we can do. Windows services are one thing they said no too. In fact,
our BL tier used to be on a separate server all together that we accessed
through Remoting where the async stuff worked fine. One of these
requirements forced us to bring the BL tier back in process on the webserver
and this is when we started running into problems.

Any ideas on how to do this in when the BL tier is running within the
asp.net web app?

"Steve C. Orr [MVP, MCSD]" <> wrote in message
news:...
> You should probably set up a Windows Service to handle such background
> tasks reliably.
> In ASP.NET threads come and go too quickly for synchronization to be of
> much use in most cases.
>
> Here's more info on Windows Services:
> http://msdn.microsoft.com/library/de...plications.asp
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
>
> "Stephen Barrett" <> wrote in message
> news:...
>>I have read many threads related to async fire and forget type calls, but
>>none have addressed my particular problem.
>>
>> I have a webpage that instantiates a BL object and makes a method call.
>> The BL object method actually sets up a delegate and calls a private
>> method asynchronously and immediately returns back to the web page.
>>
>> The problem I am having is that the async call never happens. I added a
>> quick logging call immediately as the first line of code in the method
>> that is suppose to get called asynchronously and it never gets called.
>>
>> I am using an AsyncHelper class mentioned in other posts to help get
>> around the memory leak issues regarding not calling EndInvoke after a
>> BeginInvoke.
>>
>> If I call the public method of the BL and just have it call the internal
>> one without using an async delegate, everything works fine except that
>> the webpage eventually times out because it can be a very long process.
>>
>> I am thinking about maybe spawning a new thread manually and letting
>> handle the long running process to see if I can around the issue. Any
>> ideas on how to do this asynchronously fire-and-forget within the BL
>> would be greatly appreciated.
>>

>
>



 
Reply With Quote
 
Stephen Barrett
Guest
Posts: n/a
 
      04-11-2006
I forgot to mention that is a .net 1.1 asp.net app and not a 2.0.

"Stephen Barrett" <> wrote in message
news:...
>I have read many threads related to async fire and forget type calls, but
>none have addressed my particular problem.
>
> I have a webpage that instantiates a BL object and makes a method call.
> The BL object method actually sets up a delegate and calls a private
> method asynchronously and immediately returns back to the web page.
>
> The problem I am having is that the async call never happens. I added a
> quick logging call immediately as the first line of code in the method
> that is suppose to get called asynchronously and it never gets called.
>
> I am using an AsyncHelper class mentioned in other posts to help get
> around the memory leak issues regarding not calling EndInvoke after a
> BeginInvoke.
>
> If I call the public method of the BL and just have it call the internal
> one without using an async delegate, everything works fine except that the
> webpage eventually times out because it can be a very long process.
>
> I am thinking about maybe spawning a new thread manually and letting
> handle the long running process to see if I can around the issue. Any
> ideas on how to do this asynchronously fire-and-forget within the BL would
> be greatly appreciated.
>



 
Reply With Quote
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      04-12-2006
you need to setup a background thread to do this. this is because of the
page life cycle.

1. at the start of the request a thread is selected from the pool.
2. a new instance of the page is created
3. the page lifecycle methods are called
4. the request is sent back to the iis.
5. the thread is return to the pool.

it a litle more complicated, as the thread may be returned to the pool and
new one selected during page lifecycle processing.

as you can see, when your delegate fires, the thread that started the async
request may be in the pool, destroyed, or processing the next page request.

if your site has light load, you can create a new thread everytime, if not,
you proably want one background thread, or a pool, created as needed. then
use a queue to send work to it.

note: the new thread will run as the asp.net account, not the account of the
thread creating it, so you may need to do some impersonation.

-- bruce (sqlwork.com)





"Stephen Barrett" <> wrote in message
news:...
>I have read many threads related to async fire and forget type calls, but
>none have addressed my particular problem.
>
> I have a webpage that instantiates a BL object and makes a method call.
> The BL object method actually sets up a delegate and calls a private
> method asynchronously and immediately returns back to the web page.
>
> The problem I am having is that the async call never happens. I added a
> quick logging call immediately as the first line of code in the method
> that is suppose to get called asynchronously and it never gets called.
>
> I am using an AsyncHelper class mentioned in other posts to help get
> around the memory leak issues regarding not calling EndInvoke after a
> BeginInvoke.
>
> If I call the public method of the BL and just have it call the internal
> one without using an async delegate, everything works fine except that the
> webpage eventually times out because it can be a very long process.
>
> I am thinking about maybe spawning a new thread manually and letting
> handle the long running process to see if I can around the issue. Any
> ideas on how to do this asynchronously fire-and-forget within the BL would
> be greatly appreciated.
>



 
Reply With Quote
 
Stephen Barrett
Guest
Posts: n/a
 
      04-13-2006
IS this as simple as setting the IsBackground property to TRUE when I create
the new thread?

I have tried numerous methods to get this to work.

1) create delegate to private method, and call BeginInvoke with calling
EndInvoke (memory leak possible)

2) create deleate to private method and use AsyncHelper class to basically
fire and forget

3) create a new Thread with ThreadStart pointing to private method

The private method is not getting called in any of these scenarios. Isn't
there a way to create a thread that will survive once the page life cycle
thread finishes?


"bruce barker (sqlwork.com)" <> wrote
in message news:...
> you need to setup a background thread to do this. this is because of the
> page life cycle.
>
> 1. at the start of the request a thread is selected from the pool.
> 2. a new instance of the page is created
> 3. the page lifecycle methods are called
> 4. the request is sent back to the iis.
> 5. the thread is return to the pool.
>
> it a litle more complicated, as the thread may be returned to the pool and
> new one selected during page lifecycle processing.
>
> as you can see, when your delegate fires, the thread that started the
> async request may be in the pool, destroyed, or processing the next page
> request.
>
> if your site has light load, you can create a new thread everytime, if
> not, you proably want one background thread, or a pool, created as needed.
> then use a queue to send work to it.
>
> note: the new thread will run as the asp.net account, not the account of
> the thread creating it, so you may need to do some impersonation.
>
> -- bruce (sqlwork.com)
>
>
>
>
>
> "Stephen Barrett" <> wrote in message
> news:...
>>I have read many threads related to async fire and forget type calls, but
>>none have addressed my particular problem.
>>
>> I have a webpage that instantiates a BL object and makes a method call.
>> The BL object method actually sets up a delegate and calls a private
>> method asynchronously and immediately returns back to the web page.
>>
>> The problem I am having is that the async call never happens. I added a
>> quick logging call immediately as the first line of code in the method
>> that is suppose to get called asynchronously and it never gets called.
>>
>> I am using an AsyncHelper class mentioned in other posts to help get
>> around the memory leak issues regarding not calling EndInvoke after a
>> BeginInvoke.
>>
>> If I call the public method of the BL and just have it call the internal
>> one without using an async delegate, everything works fine except that
>> the webpage eventually times out because it can be a very long process.
>>
>> I am thinking about maybe spawning a new thread manually and letting
>> handle the long running process to see if I can around the issue. Any
>> ideas on how to do this asynchronously fire-and-forget within the BL
>> would be greatly appreciated.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[J2EE] Standard asynchronous call zebulon Java 1 01-24-2006 09:30 PM
Asynchronous Call Shimon Sim ASP .Net 4 06-13-2005 03:18 AM
Re: Simple asynchronous method call Wessel Troost ASP .Net 1 04-13-2005 02:53 PM
Error in asynchronous call back function =?Utf-8?B?dnphZmZpcm8=?= ASP .Net 0 07-28-2004 12:57 PM
VB Web Service Client that Makes an Asynchronous Method Call Vicky ASP .Net 0 02-16-2004 11:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57