It's not clear from the scope of your question that the test callback is actually touching _eventFired
. This should work, however:
bool eventFired = false;
var reset = new System.Threading.ManualResetEvent(true);
cache.AddCacheLevelCallback(DataCacheOperations.AddItem | DataCacheOperations.RemoveItem,
(cacheName, region, key, itemVersion, operationId, notificationDescriptor) => {
eventFired = true;
reset.Set();
});
cache.Add(key, "my value 1");
if (!reset.WaitOne(TimeSpan.FromSeconds(10)))
{
throw new Exception("Didn't receive cache callback after 10 seconds");
}
Assert.IsTrue(eventFired);
Above I wrote the callback inline as a lambda, so that it's clear the _eventFired
gets updated on the callback. I also used a ManualResetEvent
, so that the test thread proceeds when the callback is fired, rather than waiting a hard-coded 10 seconds.