如果操作名为

时间:2017-05-25 08:52:08

标签: c# observable system.reactive

我是Reactive Extensions的新手,但使用Reactive Extensions实现以下方案的最佳方式是什么:

1-在构造函数中为每分钟订阅一个事件

2-如果某个操作被调用,那么该用户将被重置

3-如果没有发生任何事情,或者在第1步中的事件被解雇,该操作不会被召唤一分钟

这样的事情:

 public class ImportClient : Carrier<IImportService>, IImportService
{
    IObservable<long> proxyCleaner;
    void DisposeProxy(long interval)
    {
        this.Close();
        //Dispos proxy
    }
    public void RunDisposeTimer()
    {
        proxyCleaner = Observable.Interval(TimeSpan.FromMinutes(1));
        proxyCleaner.Subscribe(DisposeProxy);
    }

    public ImportClient(String endpointConfigurationName) : base(endpointConfigurationName)
    {
        RunDisposeTimer();
    }
    public Attach_DTO_OUT AttachImage(AttachImage_DTO_IN source_C)
    {
        //Reset timer here
        //Reset proxyCleaner
        using (OperationContextScope scope = new OperationContextScope(this.InnerChannel))
        {
            AddMessageHeader<Token>(Token);
            return base.Channel.AttachImage(source_C);
        }
    }
}

因为我的WCF服务是Session Full我需要在特定时间后手动处理它。

更新

我认为可以使用ObservableCollection,但如何:

  private ObservableCollection<string> collection;

    public void RunDisposeTimer()
    {
        collection = new ObservableCollection<string>();
        collection.CollectionChanged += Collection_CollectionChanged; 
    }
    private void Collection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        //Here reset timer
        throw new NotImplementedException();
    }

0 个答案:

没有答案
相关问题