SerializableDisposable(SerializationInfo info, StreamingContext context) { this._queuePath = info.GetString("queuePath"); this._serverDisposable = (IServerDisposable)info.GetValue("server", typeof(IServerDisposable)); this._subscription = (SecsEventSubscription)info.GetValue("subscription", typeof(SecsEventSubscription)); this._subscription._disposable = this; var serverLease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)_serverDisposable); if (serverLease != null) { serverLease.Register(Sponsor); } if (_subscription.Recoverable && MessageQueue.Exists(_queuePath)) { var queue = new MessageQueue(_queuePath, true, false) { Formatter = new BinaryMessageFormatter() }; queue.ReceiveCompleted += Recover; queue.BeginReceive(TimeSpan.FromSeconds(QUEUE_RECEIVE_TIMEOUT)); } else { if (MessageQueue.Exists(_queuePath)) { MessageQueue.Delete(_queuePath); } _serverDisposable.RecoverComplete(); } }
SerializableDisposable(SerializationInfo info, StreamingContext context) { this._queuePath = info.GetString("queuePath"); this._serverDisposable = (IServerDisposable)info.GetValue("server", typeof(IServerDisposable)); this._subscription = (SecsEventSubscription)info.GetValue("subscription", typeof(SecsEventSubscription)); this._subscription._disposable = this; var serverLease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)_serverDisposable); if (serverLease != null) serverLease.Register(Sponsor); if (_subscription.Recoverable && MessageQueue.Exists(_queuePath)) { var queue = new MessageQueue(_queuePath, true, false) { Formatter = new BinaryMessageFormatter() }; queue.ReceiveCompleted += Recover; queue.BeginReceive(TimeSpan.FromSeconds(QUEUE_RECEIVE_TIMEOUT)); } else { if (MessageQueue.Exists(_queuePath)) MessageQueue.Delete(_queuePath); _serverDisposable.RecoverComplete(); } }
const int QUEUE_RECEIVE_TIMEOUT = 3;//second public SerializableDisposable(SecsEventSubscription subscription, IServerDisposable serverDisposable) { _serverDisposable = serverDisposable; _subscription = subscription; _queuePath = @".\private$\" + subscription.Id; }