如何在数据库中组织 ASP.NET 请求锁定或行锁定
我有 asp.net 页面/处理程序来访问图像。 当对图像执行第一个请求时,我将图像大小调整为标准大小(保存在磁盘上)并将其返回。 所以我需要锁定除一个之外的所有对图像的请求。这将调整图像大小。 图像由 URL 中的 ID 标识,因此我猜想每一张图像(URL 中的 ID)需要一个锁定对象。 我的问题是如何组织这个锁模型?
我的想法是在应用程序中添加锁对象(应用程序是同步的) 像这样 Application.Add(Request[Id], new object()); 并用它来锁定竞争线程。
此任务类似于数据库的行锁定或锁定集合中的元素。
感谢您的重播。
I've asp.net page/handler to access images.
When performed fist request to the image I resize image to standard size(save on disk) and return it.
So I need lock all request to the image except one. This one will resize image.
Image identified by ID in URL, so I guess one lock object required per one image(ID in URL).
My question is How can I organize this lock model?
My idea add lock object in Application (Application is synchronized)
like this Application.Add(Request[Id], new object());
and use it to locking competitive threads.
This task like row locking of DB or locking element in collection.
Thanks for your replay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是锁定图像文件。
当第二个(第三个等)线程尝试创建文件时,将抛出异常“进程无法访问文件...”。我在代码中处理这个异常。
The easiest way is locking image file with.
When second(third etc) thread try to create file the Exception "The process cannot access the file ..." will throw. And I process this exception in code.