我正在使用字典通知来构建内存中的二级索引。有时(尤其是在服务升级之后),服务结构的 StateManagerChanged 事件不会对某些分区触发。这样可以防止附加 DictionaryChanged 事件,并且在基础词典进行添加/更新等操作时不会填充我的内存数据结构。我通过在 StateManagerChanged < / strong>和 DictionaryChanged 。如果我有5个分区, StateManagerChanged 有时会仅针对3个分区触发。我正在从其他2个分区中丢失通知。添加事件处理程序的代码
在服务构造函数中:
this.StateManager.StateManagerChanged += this.OnStateManagerChangedHandler;
事件处理程序
public void OnStateManagerChangedHandler(object sender, NotifyStateManagerChangedEventArgs e)
{
if (e.Action == NotifyStateManagerChangedAction.Rebuild)
{
//this.ProcessStataManagerRebuildNotification(e);
//TODO: log and return
return;
}
this.ProcessStateManagerSingleEntityNotification(e);
}
private void ProcessStateManagerSingleEntityNotification(NotifyStateManagerChangedEventArgs e)
{
var operation = e as NotifyStateManagerSingleEntityChangedEventArgs;
if (operation.Action == NotifyStateManagerChangedAction.Add)
{
if (operation.ReliableState is IReliableDictionary2<KeyObject, ValueObject> dictionary)
{
//dictionary.RebuildNotificationAsyncCallback = this.OnDictionaryRebuildNotificationHandlerAsync;
dictionary.DictionaryChanged += this.irScheduleDictionary_DictionaryChanged;
}
}
}