예외 (나를 위해 ..) 예외를 만났습니다. 단지 드물게 발생하지만,하지 ...Null 참조 기본 생성자 이후 예외
내 클래스는 정적이 아니라 하나의 정적 속성이 있습니다 :
내가 처음으로 추가하기 위해 노력하고있어static Dictionary<string, ManualResetEvent> resetEvents =
new Dictionary<string, ManualResetEvent>();
리셋 이벤트 - 때로 Null 참조 예외가 발생합니다. 인스턴스를 추가하려고하는 두 개의 다른 스레드와 관련이 있습니까?
static ManualResetEvent resetEventsGet(string key)
{
if (resetEvents.ContainsKey(key))
return resetEvents[key];
ManualResetEvent reste = new ManualResetEvent(false);
resetEvents.Add(key, reste); //System.NullReferenceException: 'Object reference not set to an instance of an object.' HOW???
return reste;
}
"시계"또는 즉치 창에서 아무 곳이나 (사전 또는 resetEvent) null이 표시되지 않습니다.
p.s - 코드가 변경되지 않았지만 이전에 결코 발생하지 않았기 때문에 visual studio 2017에 태그를 지정했습니다. 아이디어가 있으십니까? 고마워요
'ContainsKey' 호출을 지나쳐서 보이기 때문에 이상합니다. 어디서나 당신은'resetEvents = null'을 가지고 있지 않습니까? – juharr
그것은 나에게 이해가 가지 않는다. 예외가'if (resetEvents.ContainsKey (key))'줄에 표시되지 않는 이유는 무엇입니까? 코드의 다른 부분에서 해당 필드가 'null'이되지 않도록 하시겠습니까? – dcg
'new ManualResetEvent (false) '에 대한 호출은 무엇을합니까? 필드가 'null'이되지는 않습니까? – Marcello