6
我使用CacheEntryUpdateCallback委託System.Runtime.Caching圖書館有困難的時候的UpdateCallback。每當我定義和設置回調時,我都會得到一個ArgumentException,即「CacheItemUpdateCallback必須爲null」。爲什麼它一定是空的?我應該能夠設置這個,然後得到回調。完全無法定義System.Runtime.Caching
當我使用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) { }
}
優秀的,這正是我一直在尋找。 – Chris 2015-02-10 19:02:14