Re: MVC Redirect and Async Operations
I'm always wary about just launching tasks like this, threadAbort exceptions are hard to track down. Wouldn't doing this be better? Task t; Try{ t = new Task.. Redirection } finally { await task } Not sure if that would complete before or after the redirect though. A better solution would be create a log4net a sync database provider. Sent from my iPhone On 02 Aug 2015, at 00:22, Greg Keogh gfke...@gmail.com wrote: Task(()= { ... do stuff }).Start() From Framework 4.5 you have the slightly neater looking: Task.Run(() = { ...DoStuff... }); GK
RE: MVC Redirect and Async Operations
Used: ThreadPool.QueueUserWorkItem(delegate{ methodcallhere(); }); And wrapped it in an “I don’t care” error handler. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Tom Rutter Sent: Monday, 3 August 2015 9:30 AM To: ozDotNet ozdotnet@ozdotnet.com Subject: Re: MVC Redirect and Async Operations How did you end up doing it Greg? On Sat, Aug 1, 2015 at 9:51 PM, Greg Low (罗格雷格博士) g...@greglow.commailto:g...@greglow.com wrote: And implemented and working like a charm. Thanks all. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: Greg Low (罗格雷格博士) Sent: Saturday, 1 August 2015 6:26 PM To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: RE: MVC Redirect and Async Operations Thanks guys. Makes sense. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: ozdotnet-boun...@ozdotnet.commailto:ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Corneliu I. Tusnea Sent: Saturday, 1 August 2015 6:13 PM To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: Re: MVC Redirect and Async Operations Task(()= { ... do stuff }).Start() On Thu, Jul 30, 2015 at 8:06 PM, Greg Low (罗格雷格博士) g...@greglow.commailto:g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. • I don’t want the redirection to wait synchronously for the DB call to complete. • If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com
Re: MVC Redirect and Async Operations
How did you end up doing it Greg? On Sat, Aug 1, 2015 at 9:51 PM, Greg Low (罗格雷格博士) g...@greglow.com wrote: And implemented and working like a charm. Thanks all. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.com *From:* Greg Low (罗格雷格博士) *Sent:* Saturday, 1 August 2015 6:26 PM *To:* ozDotNet ozdotnet@ozdotnet.com *Subject:* RE: MVC Redirect and Async Operations Thanks guys. Makes sense. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.com *From:* ozdotnet-boun...@ozdotnet.com [ mailto:ozdotnet-boun...@ozdotnet.com ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Corneliu I. Tusnea *Sent:* Saturday, 1 August 2015 6:13 PM *To:* ozDotNet ozdotnet@ozdotnet.com *Subject:* Re: MVC Redirect and Async Operations Task(()= { ... do stuff }).Start() On Thu, Jul 30, 2015 at 8:06 PM, Greg Low (罗格雷格博士) g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. · I don’t want the redirection to wait synchronously for the DB call to complete. · If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: *www.sqldownunder.com http://www.sqldownunder.com*
RE: MVC Redirect and Async Operations
And implemented and working like a charm. Thanks all. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: Greg Low (罗格雷格博士) Sent: Saturday, 1 August 2015 6:26 PM To: ozDotNet ozdotnet@ozdotnet.com Subject: RE: MVC Redirect and Async Operations Thanks guys. Makes sense. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: ozdotnet-boun...@ozdotnet.commailto:ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Corneliu I. Tusnea Sent: Saturday, 1 August 2015 6:13 PM To: ozDotNet ozdotnet@ozdotnet.commailto:ozdotnet@ozdotnet.com Subject: Re: MVC Redirect and Async Operations Task(()= { ... do stuff }).Start() On Thu, Jul 30, 2015 at 8:06 PM, Greg Low (罗格雷格博士) g...@greglow.commailto:g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. • I don’t want the redirection to wait synchronously for the DB call to complete. • If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com
Re: MVC Redirect and Async Operations
Task(()= { ... do stuff }).Start() From Framework 4.5 you have the slightly neater looking: Task.Run(() = { ...DoStuff... }); *GK*
Re: MVC Redirect and Async Operations
Task(()= { ... do stuff }).Start() On Thu, Jul 30, 2015 at 8:06 PM, Greg Low (罗格雷格博士) g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. · I don’t want the redirection to wait synchronously for the DB call to complete. · If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: *www.sqldownunder.com http://www.sqldownunder.com*
RE: MVC Redirect and Async Operations
Thanks guys. Makes sense. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Corneliu I. Tusnea Sent: Saturday, 1 August 2015 6:13 PM To: ozDotNet ozdotnet@ozdotnet.com Subject: Re: MVC Redirect and Async Operations Task(()= { ... do stuff }).Start() On Thu, Jul 30, 2015 at 8:06 PM, Greg Low (罗格雷格博士) g...@greglow.commailto:g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. • I don’t want the redirection to wait synchronously for the DB call to complete. • If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com
Re: MVC Redirect and Async Operations
I would go with ThreadPool.QueueUserWorkItem before returning redirect response On 30 July 2015 at 20:06, Greg Low (罗格雷格博士) g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. · I don’t want the redirection to wait synchronously for the DB call to complete. · If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: *www.sqldownunder.com http://www.sqldownunder.com*
RE: MVC Redirect and Async Operations
I’ll look into those. Alternately, would it be easier to just do something like: Thread dbTask = new Thread(new SomeThreadStart(SomeParameters)); dbTask.IsBackground = true; dbTask.Start(); Response.Redirect(“somewhere”) Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com/ From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of andrew.d...@gmail.com Sent: Thursday, 30 July 2015 8:30 PM To: ozDotNet ozdotnet@ozdotnet.com Subject: Re: MVC Redirect and Async Operations async HTTP handler ? On 30 July 2015 at 20:06, Greg Low (罗格雷格博士) g...@greglow.commailto:g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. • I don’t want the redirection to wait synchronously for the DB call to complete. • If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775tel:%281300%20775%20775) office | +61 419201410tel:%2B61%20419201410 mobile│ +61 3 8676 4913tel:%2B61%203%208676%204913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com
MVC Redirect and Async Operations
One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. ・ I don’t want the redirection to wait synchronously for the DB call to complete. ・ If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.comhttp://www.sqldownunder.com
Re: MVC Redirect and Async Operations
async HTTP handler ? On 30 July 2015 at 20:06, Greg Low (罗格雷格博士) g...@greglow.com wrote: One for the MVC brains trust if I can: I want to add some basic link redirection and logging to a test MVC site. So, for example, if I have a calls like: http://www.mytestsite.com/links/10123 http://www.mytestsite.com/links/10939 I want to redirect the caller to some other URL associated with each link number. All easy enough. However, I also want to log details to my database about that call/redirection and that’s where the issue arises. · I don’t want the redirection to wait synchronously for the DB call to complete. · If the logging didn’t work, I still want the redirection to occur. I’m presuming that as soon as I return a Response.Redirect or Response.RedirectToAction, etc, etc. that I can’t then execute code afterwards in the same call. I’ve wondered about starting an async DB operation and just not waiting for it to complete. Any suggestions on how best to achieve that outcome? Is some sort of ActionFilter a better option? Thanks in advance, Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: *www.sqldownunder.com http://www.sqldownunder.com*