简体   繁体   English

.net remoting:更新已经序列化的对象

[英].net remoting: Update already serialized objects

I got a MarshalByRefObject named "DefaultMeasurement", which contains a List of IPoint-objects. 我有一个名为“DefaultMeasurement”的MarshalByRefObject,它包含一个IPoint对象列表。

public class DefaultMeasurement : MarshalByRefObject, IMeasurement
{
  private List<IPoint> iPoints;
  public this[int aIndex]
  {
    get { return iPoints[aIndex];}
  }
}

[Serializable]
public class DefaultPoint : IPoint, ISerializable
{
  public int Value {get;set;}
}

When first retrieving the DefaultMeasurement object from the server all the points get serialized and during all subsequent calls to DefaultMeasurement.Points I get the list that was correct upon startup of my client. 当第一次从服务器检索DefaultMeasurement对象时,所有点都被序列化,并且在所有后续调用DefaultMeasurement.Points期间,我得到了启动客户端时正确的列表。 But in the meantime the state of at least one object in that list might have changed and I don't get that current state, although in the server that state gets updated. 但与此同时,该列表中至少有一个对象的状态可能已更改,并且我没有获得当前状态,尽管在服务器中状态得到更新。 How do I force an update of that list? 如何强制更新该列表?

further clarification: 进一步澄清:
- it will work once I do DefaultPoint : MarshalByRefObject , but that is not an option as it negatively affects performance - 一旦我执行DefaultPoint : MarshalByRefObject ,它将起作用,但这不是一个选项,因为它会对性能产生负面影响
- by 'update' I mean changes to existing objects on the server, no adding / removing on the list itself - 'update'是指对服务器上现有对象的更改,不在列表本身上添加/删除
- I might have up to 80k DefaultPoint objects - 我可能有多达80k的DefaultPoint对象

Since you don't want the Point itself to be MarshalByRef (as that introduces a LOT of traffic if you have a substantial number of points), what I would recommend is that you have explicit methods that synchronize point values. 既然你不希望Point本身成为MarshalByRef(因为如果你有大量的点,它会引入很多流量),我建议你有明确的方法来同步点值。 After you've made a significant number of changes on the server, you call the SynchronizePoints() method, which includes new values for all of the points. 在服务器上进行了大量更改后,可以调用SynchronizePoints()方法,该方法包括所有点的新值。 Now the client-side proxy has an updated state. 现在,客户端代理具有更新状态。 Better yet, remove the state from the object in the first place (since it's not really a direct reflection of server state) and instead use client-side objects that are instantiated as needed when gathering points from the server. 更好的是,首先从对象中删除状态(因为它实际上不是服务器状态的直接反映),而是使用在从服务器收集点时根据需要实例化的客户端对象。

You would have to implement a callback that notifies the client of changes on the server. 您必须实现一个回调,通知客户端服务器上的更改。

The notify could pass id of the objects that have changed or the client could ask for a list of changed objects. 通知可以传递已更改的对象的ID,或者客户端可以请求更改的对象列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM