{"action":"created","issue":{"url":"https://api.github.com/repos/mspnp/semantic-logging/issues/19","labels_url":"https://api.github.com/repos/mspnp/semantic-logging/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/mspnp/semantic-logging/issues/19/comments","events_url":"https://api.github.com/repos/mspnp/semantic-logging/issues/19/events","html_url":"https://github.com/mspnp/semantic-logging/issues/19","id":74423035,"number":19,"title":"ObservableEventListener hangs on Dispose","user":{"login":"dkholod","id":3406251,"avatar_url":"https://avatars.githubusercontent.com/u/3406251?v=3","gravatar_id":"","url":"https://api.github.com/users/dkholod","html_url":"https://github.com/dkholod","followers_url":"https://api.github.com/users/dkholod/followers","following_url":"https://api.github.com/users/dkholod/following{/other_user}","gists_url":"https://api.github.com/users/dkholod/gists{/gist_id}","starred_url":"https://api.github.com/users/dkholod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkholod/subscriptions","organizations_url":"https://api.github.com/users/dkholod/orgs","repos_url":"https://api.github.com/users/dkholod/repos","events_url":"https://api.github.com/users/dkholod/events{/privacy}","received_events_url":"https://api.github.com/users/dkholod/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-08T16:45:45Z","updated_at":"2016-01-14T20:36:54Z","closed_at":null,"body":"I'm using the flowing code to initialize and subscribe to ObservableEventListener.\r\n\r\n```C#\r\nvar listener = new ObservableEventListener();\r\n            listener.EnableEvents(\r\n            SampleEventSource.Log,\r\n            EventLevel.LogAlways,\r\n            Keywords.All);\r\n\r\n            listener\r\n                .FlushOnTrigger(entry => entry.Schema.Keywords == SampleEventSource.Keywords.Exceptions, bufferSize: 2)\r\n                .Subscribe(new DebugObserver());\r\n\r\n            SampleEventSource.Log.ApiTiming(\"test\", \"should_work\", 1);\r\n            SampleEventSource.Log.Exception(typeof(ArgumentException).FullName, \"Wrong argument\");\r\n            listener.Dispose();\r\n```\r\n```C#\r\n public static IObservable<T> FlushOnTrigger<T>(this IObservable<T> stream, Func<T, bool> shouldFlush, int bufferSize)\r\n {\r\n     return stream\r\n    .Buffer(() => stream.SkipWhile(i => !shouldFlush(i)))\r\n    .SelectMany(l => l.Reverse().Take(bufferSize + 1).Reverse());\r\n}\r\n```\r\n\r\nIt happens to hang on listener.Dispose();\r\n\r\nWith a brief investigation I've noticed that it hangs in [EventEntrySubject.cs](https://github.com/mspnp/semantic-logging/blob/master/source/Src/SemanticLogging/Observable/EventEntrySubject.cs) OnCompleted method.\r\n\r\n```C#\r\npublic void OnCompleted()\r\n{\r\n            var currentObservers = this.TakeObserversAndFreeze();\r\n\r\n            if (currentObservers != null)\r\n            {\r\n                Parallel.ForEach(currentObservers, observer => observer.OnCompleted());\r\n            }\r\n}\r\n```\r\nIn case the parallel loop is replaced with non-parallel statement everything works well.\r\nBefore loop execution the observers collection is the flowing:\r\n![image](https://cloud.githubusercontent.com/assets/3406251/7541002/734a088a-f5ba-11e4-8766-0d01920e2a35.png)\r\n\r\nPlease advise.\r\n"},"comment":{"url":"https://api.github.com/repos/mspnp/semantic-logging/issues/comments/171772336","html_url":"https://github.com/mspnp/semantic-logging/issues/19#issuecomment-171772336","issue_url":"https://api.github.com/repos/mspnp/semantic-logging/issues/19","id":171772336,"user":{"login":"mekoda","id":2442939,"avatar_url":"https://avatars.githubusercontent.com/u/2442939?v=3","gravatar_id":"","url":"https://api.github.com/users/mekoda","html_url":"https://github.com/mekoda","followers_url":"https://api.github.com/users/mekoda/followers","following_url":"https://api.github.com/users/mekoda/following{/other_user}","gists_url":"https://api.github.com/users/mekoda/gists{/gist_id}","starred_url":"https://api.github.com/users/mekoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mekoda/subscriptions","organizations_url":"https://api.github.com/users/mekoda/orgs","repos_url":"https://api.github.com/users/mekoda/repos","events_url":"https://api.github.com/users/mekoda/events{/privacy}","received_events_url":"https://api.github.com/users/mekoda/received_events","type":"User","site_admin":false},"created_at":"2016-01-14T20:36:54Z","updated_at":"2016-01-14T20:36:54Z","body":"@mhorn69 are you using the same filter?"}}