windows服务与Remoting对象交互问题
现欲实现以下功能,实现一缓存,用户调用remoting对象的时候,都可以从该缓存中取到数据,同时也有远程方法可以设置该缓存的值。该缓存状态是一直存在的。
具体设想如下:在windows服务中加载remoting对象,该对象中有一全局变量,租约期设为无限。现希望可以在服务中,每隔一段时间就更新该全局变量的值,该如何实现这个功能,请指教!
代码如下:
定时器服务代码:
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//调用 设置remoting对象的更新变量的方法(如何实现?)调用GetStr111()这个方法。
}
remoting对象代码:
public class RemotingExampleService : MarshalByRefObject, IRemotingExampleService
{
protected int i = 0; //全局缓存
public string GetStr()
{
return (i++).ToString();
}
//重新设置全局变量的方法
public string GetStr111()
{
i = 1;
return i.ToString();
}
}