0

Normally, billings should execute in the background on a scheduled date (I haven't figured out how to do that yet, but that's another topic).

But occasionally, the user may wish to execute a billing manually. Once clicked, I would like to be sure the operation runs to completion regardless of what happens on the user side (e.g. closes browser, machine dies, network goes down, whatever).

I'm pretty sure db.SaveChanges() wraps its DB operations in a transaction, so from a server perspective I believe the whole thing will either finish or fail, with no partial effect.

But what about all the work between the POST and the db.SaveChanges()? Is there a way to be sure the user can't inadvertently or intentionally stop that from completing?

I guess a corollary to this question is what happens to a running Asynchronous Controller or a running Task or Thread if the user disconnects?

4

1 に答える 1

0

My previous project was actually doing a billing system in MVC. I distinctly remember testing out what would happen if I used Task and then quickly exited the site. It did all of the calculations just fine, ran a stored procedure in SQL Server, and sent me an e-mail when it was done.

So, to answer your question: If you wrap the operations in a Task it should finish anyways with no problems.

于 2013-02-21T16:37:46.073 に答える