隊ConfigurationErrorsException-該進程無法訪問該文件「C: eventlog.config」,因爲它正被另一個進程使用
我有這段代碼總是佔用了本身的一種競爭狀態尤其是當兩個或更多資源正試圖同時寫入eventlog.config文件時。我搜索了幾個頻道,但無法解決這個錯誤。任何人都可以幫助我修改此代碼,以便我可以刪除競爭條件。
private void UpdateLastEventId(IList<EventLogEntry> entries)
{
if (entries.Count > 0)
{
EventLogEntry lastEntry = entries[entries.Count - 1];
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var configSettings = config.AppSettings.Settings;
string key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", _eventLogFilter.EventLog, _eventLogFilter.MD5Hash);
if (configSettings[key] == null)
{
configSettings.Add(key, lastEntry.Index.ToString(CultureInfo.InvariantCulture));
}
else
{
configSettings[key].Value = lastEntry.Index.ToString(CultureInfo.InvariantCulture);
}
config.Save(ConfigurationSaveMode.Modified);//Error seems to happen here
}
}
有你的閱讀[在此文檔(https://msdn.microsoft.com/en-us/library/ms134088(V = vs.110)的.aspx) – MethodMan