From: kichankwon <35328573+kichankwon@users.noreply.github.com> Date: Thu, 18 Jan 2018 10:01:31 +0000 (+0900) Subject: [Information] Fix delegate lifetime issue (#52) X-Git-Tag: submit/tizen_4.0/20180118.101305~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e22a8fc20f5899a8edb5111af0a0caf5d44f20f;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Information] Fix delegate lifetime issue (#52) Signed-off-by: kichankwon --- diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs index 011073afc..8dde55d5c 100755 --- a/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs +++ b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs @@ -29,13 +29,33 @@ namespace Tizen.System Handler = null; } + private static Interop.RuntimeInfo.RuntimeInformationChangedCallback __callback; + internal event EventHandler EventHandler { add { if (Handler == null) { - InformationError ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(TvProductHelper.ConvertKeyIfTvProduct(Key), RuntimeInformationChangedCallback, IntPtr.Zero); + __callback = (RuntimeInfoKey num, IntPtr userData) => + { + string strKey = "Invalid"; + RuntimeInfoKey key = TvProductHelper.ReconvertKeyIfTvProduct(num); + + if (key > 0 && Information.EnumStringMapping.ContainsKey(key)) + { + strKey = Information.EnumStringMapping[key]; + } + + RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs() + { + Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + strKey + }; + + Handler?.Invoke(null, eventArgs); + }; + + InformationError ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(TvProductHelper.ConvertKeyIfTvProduct(Key), __callback, IntPtr.Zero); if (ret != InformationError.None) { Log.Error(InformationErrorFactory.LogTag, "Interop failed to add event handler"); @@ -58,23 +78,5 @@ namespace Tizen.System } } } - - private void RuntimeInformationChangedCallback(RuntimeInfoKey num, IntPtr userData) - { - string strKey = "Invalid"; - RuntimeInfoKey key = TvProductHelper.ReconvertKeyIfTvProduct(num); - - if (key > 0 && Information.EnumStringMapping.ContainsKey(key)) - { - strKey = Information.EnumStringMapping[key]; - } - - RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs() - { - Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + strKey - }; - - Handler?.Invoke(null, eventArgs); - } } }