[Connection][WiFi] Use TizenSynchronizationContext.Post for asynchronous methods...
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionProfile.cs
index e234476..9ba3f3a 100755 (executable)
@@ -19,6 +19,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Runtime.InteropServices;
+using Tizen.Applications;
 
 namespace Tizen.Network.Connection
 {
@@ -36,6 +37,8 @@ namespace Tizen.Network.Connection
 
         private Interop.ConnectionProfile.ProfileStateChangedCallback _profileChangedCallback;
 
+        private TizenSynchronizationContext context = new TizenSynchronizationContext();
+
         internal IntPtr GetHandle()
         {
             return ProfileHandle;
@@ -55,20 +58,26 @@ namespace Tizen.Network.Connection
             add
             {
                 Log.Debug(Globals.LogTag, "ProfileStateChanged add");
-                if (_ProfileStateChanged == null)
+                context.Post((x) =>
                 {
-                    ProfileStateChangedStart();
-                }
-                _ProfileStateChanged += value;
+                    if (_ProfileStateChanged == null)
+                    {
+                        ProfileStateChangedStart();
+                    }
+                    _ProfileStateChanged += value;
+                }, null);
             }
             remove
             {
                 Log.Debug(Globals.LogTag, "ProfileStateChanged remove");
-                _ProfileStateChanged -= value;
-                if (_ProfileStateChanged == null)
+                context.Post((x) =>
                 {
-                    ProfileStateChangedStop();
-                }
+                    _ProfileStateChanged -= value;
+                    if (_ProfileStateChanged == null)
+                    {
+                        ProfileStateChangedStop();
+                    }
+                }, null);
             }
         }
 
@@ -76,6 +85,7 @@ namespace Tizen.Network.Connection
         {
             _profileChangedCallback = (ProfileState state, IntPtr userData) =>
             {
+                Log.Info(Globals.LogTag, "***** MOON ProfileStateChanged occur");
                 if (_ProfileStateChanged != null)
                 {
                     _ProfileStateChanged(null, new ProfileStateEventArgs(state));
@@ -107,6 +117,9 @@ namespace Tizen.Network.Connection
             IPv6 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.IPv6);
         }
 
+        /// <summary>
+        /// Destroy the ConnectionProfile object
+        /// </summary>
         ~ConnectionProfile()
         {
             Dispose(false);
@@ -128,12 +141,9 @@ namespace Tizen.Network.Connection
             if (disposed)
                 return;
 
-            if (disposing)
-            {
-                // Free managed objects.
-                UnregisterEvents();
-                Destroy();
-            }
+            // Free unmanaged objects
+            UnregisterEvents();
+            Destroy();
             disposed = true;
         }