简体   繁体   English

防止多个线程运行同一后台进程

[英]Preventing multiple threads from running same background process

I have an asp.net website with a background service running that sends queued emails every minute. 我有一个运行后台服务的asp.net网站,每分钟都会发送排队的电子邮件。 The problem is we moved to a web garden (multiple worker processes) and the emails get sent multiple times (at the very same time or close to it) because multiple threads are invoking that background process. 问题是我们移到了一个网络花园(多个工作进程),并且由于多个线程正在调用该后台进程,因此多次发送了电子邮件(同时或接近它)。

Is there a way to assign one thread or have only one thread run this process every minute and tell the other ones to ignore it? 有没有一种方法可以分配一个线程,或者只有一个线程每分钟运行一次此进程,并告诉其他线程忽略它?

Thanks! 谢谢!

我必须使用互斥锁来防止这种情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM