【发布时间】:2015-04-10 19:10:57
【问题描述】:
我在使用 System.Runtime.Caching 库的 CacheEntryUpdateCallback 委托时遇到了困难。每当我定义和设置回调时,我都会收到一个 ArgumentException,即“CacheItemUpdateCallback 必须为空”。为什么它必须为空?我应该可以设置这个然后得到回调。
我在使用 CacheEntryRemovedCallback 委托时没有收到此信息。我可以在我的所有项目中可靠地重现这一点。难道我做错了什么?这是一个小示例应用程序:
using System.Runtime.Caching;
class Program {
static void Main(string[] args) {
var policy = new CacheItemPolicy();
policy.SlidingExpiration = TimeSpan.FromSeconds(10);
// this works
//policy.RemovedCallback = Removed;
// this creates the exception
policy.UpdateCallback = Update;
MemoryCache.Default.Add("test", "123", policy);
Console.Read();
}
static void Update(CacheEntryUpdateArguments arguments) { }
static void Removed(CacheEntryRemovedArugments arguments) { }
}
【问题讨论】: