这个代码在带有lucene索引2.1.3的visual studio 2005中运行良好但是当我在带有lucene 2.9.2的visual studio 2010中尝试这个代码时,它会遇到Catch(异常)。根本没有代码更改。因此,索引器无法使用lucene 2.9.2在2010视觉工作室中搜索任何内容。
private static Mutex _mutex;
private const string MUTEX_NAME = "Global\\ef89ca90-0196-11dd-95ff-0800200c9a66";
//if changed make sure both the website and windows service is updated
try
{
//try to get the existing mutex
_mutex = Mutex.OpenExisting(MUTEX_NAME, MutexRights.FullControl);
}
catch (Exception)
{
//if there was an exception, the mutex didn't exist so create it
MutexSecurity mutexSecurity = new MutexSecurity();
mutexSecurity.AddAccessRule(new MutexAccessRule("Everyone", MutexRights.FullControl, AccessControlType.Allow));
bool createdNew;
_mutex = new Mutex(false, MUTEX_NAME, out createdNew, mutexSecurity);
}
我也同时升级到.Net 4.0,并认为它可能是索引文件夹上的权限问题。我授予ASP.Net机器帐户和IIS_WPG的权限,然后是所有人。网络运行在trust = Full,相应的项目允许不安全的代码(以前的lucene bug),所以我很难过。
我嘲笑它有用的帮助。但现在我意识到问题出在Mutex名称上。