Reliable Use of UmbracoDatabase from Background Thread?
I am inserting a record into the database from a background thread (to avoid slowing down a form submission): GitHub
I am using an instance of UmbracoDatabase, which implements IDisposeOnRequestEnd. For whatever reason, this seems to work currently, at least most of the time (my theory is that the database insert is so fast it finishes before the request ends and disposes of the database).
If the database is disposed of at the end of a request, what is the recommended way to reliably interact with the database from a background thread?
Lightweight Needs to be lightweight solution. Can't go all willy nilly modifying config files and changing major default bits of architecture for a site.
Retain Abstractions Can't just bypass Umbraco's database abstractions by accessing connection string. This is for an open source tool that may be used on thousands of installs, so need to use core-supported methods (e.g., so it will work on SQL Server, SQL Server CE, and MySql).
I imagine there is a very simple way of addressing this. I just don't know what it is yet.
Does anybody know of a safe way to interact with the Umbraco database from a background thread? I just found another use case I'll be needing shortly.
Specifically, I plan on incrementing a page view count, which will facilitate a tool that allows blog articles to be sorted by popularity (popularity being determined by number of page views). I'd like to perform the database update on a background thread so it doesn't slow down the display of the blog article pages.
Reliable Use of UmbracoDatabase from Background Thread?
I am inserting a record into the database from a background thread (to avoid slowing down a form submission): GitHub
I am using an instance of
UmbracoDatabase
, which implementsIDisposeOnRequestEnd
. For whatever reason, this seems to work currently, at least most of the time (my theory is that the database insert is so fast it finishes before the request ends and disposes of the database).If the database is disposed of at the end of a request, what is the recommended way to reliably interact with the database from a background thread?
FYI, this question was initiated based on some information Shannon wrote here (regarding how the database is disposed): https://github.com/kipusoep/UrlTracker/issues/146
Also, while you probably don't need to know this, you can see the thread creation here: GitHub
To add some clarifications to my original question, there is some discussion on Twitter about this: https://twitter.com/MrMarsRed/status/880513267310895104
Some important points:
I imagine there is a very simple way of addressing this. I just don't know what it is yet.
Does anybody know of a safe way to interact with the Umbraco database from a background thread? I just found another use case I'll be needing shortly.
Specifically, I plan on incrementing a page view count, which will facilitate a tool that allows blog articles to be sorted by popularity (popularity being determined by number of page views). I'd like to perform the database update on a background thread so it doesn't slow down the display of the blog article pages.
is working on a reply...