unsubscribe

Angular2: Unsubscribe from http observable in Service

北战南征 提交于 2019-11-27 12:46:51
问题 What is the best practice to unsubscribe within a Angular2 service from a http subscription? Currently I do this but I'm not sure if this will be the best way. import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import { Subject } from "rxjs/Subject"; import { ISubscription } from "rxjs/Subscription"; @Injectable() export class SearchService { private _searchSource = new Subject<any>(); public search$ = this._searchSource.asObservable(); constructor(private _http

Should I unsubscribe from events? [duplicate]

寵の児 提交于 2019-11-27 11:26:57
This question already has an answer here: Is it bad to not unregister event handlers? 2 answers I have 3 questions concerning events: Should I always unsubscribe events that were subscribed? What happens if I do NOT? In the below examples, how would you unsubscribe from the subscribed events? I have for example this code: Ctor: Purpose: For database property updates this.PropertyChanged += (o, e) => { switch (e.PropertyName) { case "FirstName": break; case "LastName": break; } }; and this: Purpose: For GUI-binding wrap the model into viewmodels ObservableCollection<Period> periods = _lpRepo

Should I unsubscribe from events? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-11-27 04:02:43
问题 This question already has an answer here: Is it bad to not unregister event handlers? 2 answers I have 3 questions concerning events: Should I always unsubscribe events that were subscribed? What happens if I do NOT? In the below examples, how would you unsubscribe from the subscribed events? I have for example this code: Ctor: Purpose: For database property updates this.PropertyChanged += (o, e) => { switch (e.PropertyName) { case "FirstName": break; case "LastName": break; } }; and this:

Using IDisposable to unsubscribe events

泪湿孤枕 提交于 2019-11-26 09:24:45
问题 I have a class that handles events from a WinForms control. Based on what the user is doing, I am deferencing one instance of the class and creating a new one to handle the same event. I need to unsubscribe the old instance from the event first - easy enough. I\'d like to do this in a non-proprietary manner if possible, and it seems like this is a job for IDisposable. However, most documentation recommends IDisposable only when using unmanaged resources, which does not apply here. If I