[Tizen.Network.WiFi] Remove thread local support (#6708)
authorsaksham9891 <s.grover@partner.samsung.com>
Wed, 12 Mar 2025 02:48:11 +0000 (08:18 +0530)
committerGitHub <noreply@github.com>
Wed, 12 Mar 2025 02:48:11 +0000 (11:48 +0900)
* Remove TizenSynchronizationContext.post()

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
* Remove thread local

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
---------

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
Co-authored-by: Akash Kumar <akash1.kumar@samsung.com>
src/Tizen.Network.WiFi/Tizen.Network.WiFi.csproj
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs

index 7e50267de1bbce9af74fb976864f372f8bf0f040..e0d5237e89a70206a8914102a12348e33160a021 100644 (file)
@@ -6,7 +6,6 @@
 
   <ItemGroup>
     <ProjectReference Include="..\Tizen.Network.Connection\Tizen.Network.Connection.csproj" />
-    <ProjectReference Include="..\Tizen.Applications.Common\Tizen.Applications.Common.csproj" />
   </ItemGroup>
 
 </Project>
index a4b5f4eb6cc17747fc543736d2313b3d85fa632b..55c6fd4865806b4d08f9e418be977237e9156909 100644 (file)
@@ -17,7 +17,6 @@
 using System;
 using System.Threading.Tasks;
 using System.Collections.Generic;
-using Tizen.Applications;
 
 namespace Tizen.Network.WiFi
 {
@@ -38,8 +37,6 @@ namespace Tizen.Network.WiFi
 
         private static TaskCompletionSource<WiFiAP> wpsWithoutSsidTask = null;
         private static Dictionary<IntPtr, TaskCompletionSource<bool>> _wpsTaskMap = new Dictionary<IntPtr, TaskCompletionSource<bool>>();
-        private TizenSynchronizationContext context = new TizenSynchronizationContext();
-        private static TizenSynchronizationContext s_context = new TizenSynchronizationContext();
 
         /// <summary>
         /// The network information of the access point (AP).
@@ -255,32 +252,29 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.Connect");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.Connect");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
-                    }
-                    if (ret != (int)WiFiError.None)
-                    {
-                        Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
-                        if (ret == (int)WiFiError.InvalidParameterError)
-                        {
-                            throw new InvalidOperationException("Invalid handle");
-                        }
-                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
-                    }
+                    ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
                 }
-                catch (Exception e)
+                if (ret != (int)WiFiError.None)
                 {
-                    Log.Error(Globals.LogTag, "Exception on ConnectAsync\n" + e);
-                    task.SetException(e);
+                    Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+                    if (ret == (int)WiFiError.InvalidParameterError)
+                    {
+                        throw new InvalidOperationException("Invalid handle");
+                    }
+                    WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
                 }
-            }, null);
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ConnectAsync\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -345,47 +339,44 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            try
             {
-                try
+                int ret = -1;
+                if (info.GetType() == typeof(WpsPbcInfo))
                 {
-                    int ret = -1;
-                    if (info.GetType() == typeof(WpsPbcInfo))
-                    {
-                        Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb");
-                        ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
-                    }
-                    else if (info.GetType() == typeof(WpsPinInfo))
+                    Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb");
+                    ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+                }
+                else if (info.GetType() == typeof(WpsPinInfo))
+                {
+                    WpsPinInfo pinInfo = (WpsPinInfo)info;
+                    if (pinInfo.GetWpsPin() == null)
                     {
-                        WpsPinInfo pinInfo = (WpsPinInfo)info;
-                        if (pinInfo.GetWpsPin() == null)
-                        {
-                            throw new ArgumentNullException("Wps pin should not be null");
-                        }
-
-                        if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8)
-                        {
-                            throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters");
-                        }
-
-                        Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin");
-                        ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id);
+                        throw new ArgumentNullException("Wps pin should not be null");
                     }
 
-                    if (ret != (int)WiFiError.None)
+                    if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8)
                     {
-                        Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
-                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+                        throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters");
                     }
+
+                    Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin");
+                    ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id);
                 }
-                catch (Exception e)
+
+                if (ret != (int)WiFiError.None)
                 {
-                    Log.Error(Globals.LogTag, "Exception on ConnectWpsAsync\n" + e);
-                    wpsTask.SetException(e);
-                    Log.Info(Globals.LogTag, "Remove task for ConnectWpsAsync");
-                    _wpsTaskMap.Remove(_apHandle);
+                    Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+                    WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
                 }
-            }, null);
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ConnectWpsAsync\n" + e);
+                wpsTask.SetException(e);
+                Log.Info(Globals.LogTag, "Remove task for ConnectWpsAsync");
+                _wpsTaskMap.Remove(_apHandle);
+            }
 
             return wpsTask.Task;
         }
@@ -445,47 +436,44 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            s_context.Post((x) =>
+            try
             {
-                try
+                int ret = -1;
+                if (info.GetType() == typeof(WpsPbcInfo))
                 {
-                    int ret = -1;
-                    if (info.GetType() == typeof(WpsPbcInfo))
-                    {
-                        Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid");
-                        ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
-                    }
-                    else if (info.GetType() == typeof(WpsPinInfo))
+                    Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid");
+                    ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
+                }
+                else if (info.GetType() == typeof(WpsPinInfo))
+                {
+                    WpsPinInfo pinInfo = (WpsPinInfo)info;
+                    if (pinInfo.GetWpsPin() == null)
                     {
-                        WpsPinInfo pinInfo = (WpsPinInfo)info;
-                        if (pinInfo.GetWpsPin() == null)
-                        {
-                            throw new ArgumentNullException("Wps pin should not be null");
-                        }
-
-                        if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
-                        {
-                            throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
-                        }
-
-                        Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid");
-                        ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
+                        throw new ArgumentNullException("Wps pin should not be null");
                     }
 
-                    if (ret != (int)WiFiError.None)
+                    if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
                     {
-                        Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
-                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
+                        throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
                     }
+
+                    Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid");
+                    ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
                 }
-                catch (Exception e)
+
+                if (ret != (int)WiFiError.None)
                 {
-                    Log.Error(Globals.LogTag, "Exception on ConnectWpsWithoutSsidAsync\n" + e);
-                    wpsWithoutSsidTask.SetException(e);
-                    wpsWithoutSsidTask = null;
-                    Log.Info(Globals.LogTag, "task is null");
+                    Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+                    WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
                 }
-            }, null);
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ConnectWpsWithoutSsidAsync\n" + e);
+                wpsWithoutSsidTask.SetException(e);
+                wpsWithoutSsidTask = null;
+                Log.Info(Globals.LogTag, "task is null");
+            }
 
             return wpsWithoutSsidTask.Task;
         }
@@ -574,28 +562,25 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.Disconnect");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.Disconnect");
-                try
+                int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+                if (ret != (int)WiFiError.None)
                 {
-                    int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
-                    if (ret != (int)WiFiError.None)
+                    Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret);
+                    if (ret == (int)WiFiError.InvalidParameterError)
                     {
-                        Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret);
-                        if (ret == (int)WiFiError.InvalidParameterError)
-                        {
-                            throw new InvalidOperationException("Invalid handle");
-                        }
-                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+                        throw new InvalidOperationException("Invalid handle");
                     }
+                    WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
                 }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on Disconnect\n" + e);
-                    task.SetException(e);
-                }
-            }, null);
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on Disconnect\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -679,28 +664,25 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.ForgetAP");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.ForgetAP");
-                try
+                int ret = Interop.WiFi.ForgetAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+                if (ret != (int)WiFiError.None)
                 {
-                    int ret = Interop.WiFi.ForgetAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
-                    if (ret != (int)WiFiError.None)
+                    Log.Error(Globals.LogTag, "Failed to forget wifi, Error - " + (WiFiError)ret);
+                    if (ret == (int)WiFiError.InvalidParameterError)
                     {
-                        Log.Error(Globals.LogTag, "Failed to forget wifi, Error - " + (WiFiError)ret);
-                        if (ret == (int)WiFiError.InvalidParameterError)
-                        {
-                            throw new InvalidOperationException("Invalid handle");
-                        }
-                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+                        throw new InvalidOperationException("Invalid handle");
                     }
+                    WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
                 }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on ForgetAPAsync\n" + e);
-                    task.SetException(e);
-                }
-            }, null);
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ForgetAPAsync\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
index 6853444473e36ce905422c88695c73ed70388db4..38cc5e264f287e1c35587eb49f30ffa53e2d1d12 100644 (file)
@@ -19,7 +19,6 @@ using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Runtime.InteropServices;
-using Tizen.Applications;
 
 namespace Tizen.Network.WiFi
 {
@@ -50,8 +49,6 @@ namespace Tizen.Network.WiFi
         private static readonly Lazy<WiFiManagerImpl> _instance =
             new Lazy<WiFiManagerImpl>(() => new WiFiManagerImpl());
 
-        private TizenSynchronizationContext context = new TizenSynchronizationContext();
-
         private Dictionary<IntPtr, Interop.WiFi.VoidCallback> _callback_map =
             new Dictionary<IntPtr, Interop.WiFi.VoidCallback>();
 
@@ -153,11 +150,7 @@ namespace Tizen.Network.WiFi
             }
         }
 
-        private static ThreadLocal<HandleHolder> s_threadName = new ThreadLocal<HandleHolder>(() =>
-        {
-            Log.Info(Globals.LogTag, "In threadlocal delegate");
-            return new HandleHolder();
-        });
+        private static HandleHolder _handle = new HandleHolder();
 
         private WiFiManagerImpl()
         {
@@ -166,7 +159,7 @@ namespace Tizen.Network.WiFi
 
         internal SafeWiFiManagerHandle GetSafeHandle()
         {
-            return s_threadName.Value.GetSafeHandle();
+            return _handle.GetSafeHandle();
         }
 
         internal SafeWiFiManagerHandle Initialize()
@@ -331,24 +324,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.ActivateAsync");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.ActivateAsync");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "Activate", "");
+                    ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id);
                 }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on ActivateAsync\n" + e);
-                    task.SetException(e);
-                }
-            }, null);
+                CheckReturnValue(ret, "Activate", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ActivateAsync\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -380,24 +370,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.ActivateWithWiFiPickerTestedAsync");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.ActivateWithWiFiPickerTestedAsync");
-                try
-                {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "ActivateWithWiFiPickerTested", "");
-                }
-                catch (Exception e)
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    Log.Error(Globals.LogTag, "Exception on ActivateWithWiFiPickerTestedAsync\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "ActivateWithWiFiPickerTested", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ActivateWithWiFiPickerTestedAsync\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -429,24 +416,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.Deactivate");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.Deactivate");
-                try
-                {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "Deactivate", "");
-                }
-                catch (Exception e)
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    Log.Error(Globals.LogTag, "Exception on Deactivate\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "Deactivate", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on Deactivate\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -478,24 +462,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.Scan");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.Scan");
-                try
-                {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "Scan", "");
-                }
-                catch (Exception e)
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    Log.Error(Globals.LogTag, "Exception on Scan\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "Scan", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on Scan\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -527,24 +508,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.ScanSpecificAPAsync");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.ScanSpecificAPAsync");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "ScanSpecificAP", "");
+                    ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id);
                 }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on ScanSpecificAPAsync\n" + e);
-                    task.SetException(e);
-                }
-            }, null);
+                CheckReturnValue(ret, "ScanSpecificAP", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on ScanSpecificAPAsync\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -576,24 +554,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.BssidScan");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.BssidScan");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.BssidScan(GetSafeHandle(), _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "BssidScan", "");
-                }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on BssidScan\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.BssidScan(GetSafeHandle(), _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "BssidScan", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on BssidScan\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -632,24 +607,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.HiddenAPConnect");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.HiddenAPConnect");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.ConnectHiddenAP(GetSafeHandle(), essid, secType, passphrase, _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "HiddenAPConnect", "");
-                }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on HiddenAPConnect\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.ConnectHiddenAP(GetSafeHandle(), essid, secType, passphrase, _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "HiddenAPConnect", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on HiddenAPConnect\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
@@ -703,24 +675,21 @@ namespace Tizen.Network.WiFi
                 };
             }
 
-            context.Post((x) =>
+            Log.Info(Globals.LogTag, "Interop.WiFi.SpecificApStartMultiScan");
+            try
             {
-                Log.Info(Globals.LogTag, "Interop.WiFi.SpecificApStartMultiScan");
-                try
+                int ret = (int)WiFiError.None;
+                lock (_callback_map)
                 {
-                    int ret = (int)WiFiError.None;
-                    lock (_callback_map)
-                    {
-                        ret = Interop.WiFi.SpecificApStartMultiScan(GetSafeHandle(), _specificScanHandle, _callback_map[id], id);
-                    }
-                    CheckReturnValue(ret, "MultiScan", "");
-                }
-                catch (Exception e)
-                {
-                    Log.Error(Globals.LogTag, "Exception on Multi Scan\n" + e);
-                    task.SetException(e);
+                    ret = Interop.WiFi.SpecificApStartMultiScan(GetSafeHandle(), _specificScanHandle, _callback_map[id], id);
                 }
-            }, null);
+                CheckReturnValue(ret, "MultiScan", "");
+            }
+            catch (Exception e)
+            {
+                Log.Error(Globals.LogTag, "Exception on Multi Scan\n" + e);
+                task.SetException(e);
+            }
 
             return task.Task;
         }
index 3db144d3ba089617c9d9fc6f6d38ce7e10c38305..a4ef36922f0a6e469ff7a5d8a9e75f58d0716c0b 100755 (executable)
@@ -59,39 +59,34 @@ namespace Tizen.Network.WiFi
         {
             add
             {
-                context.Post((x) =>
+                if (_deviceStateChanged == null)
                 {
-                    if (_deviceStateChanged == null)
+                    try
                     {
-                        try
-                        {
-                            RegisterDeviceStateChangedEvent();
-                        } catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on adding DeviceStateChanged\n" + e);
-                            return;
-                        }
+                        RegisterDeviceStateChangedEvent();
                     }
-                    _deviceStateChanged += value;
-                }, null);
+                    catch (Exception e)
+                    {
+                        Log.Error(Globals.LogTag, "Exception on adding DeviceStateChanged\n" + e);
+                        return;
+                    }
+                }
+                _deviceStateChanged += value;
             }
             remove
             {
-                context.Post((x) =>
+                _deviceStateChanged -= value;
+                if (_deviceStateChanged == null)
                 {
-                    _deviceStateChanged -= value;
-                    if (_deviceStateChanged == null)
+                    try
+                    {
+                        UnregisterDeviceStateChangedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            UnregisterDeviceStateChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on removing DeviceStateChanged\n" + e);
-                        }
+                        Log.Error(Globals.LogTag, "Exception on removing DeviceStateChanged\n" + e);
                     }
-                }, null);
+                }
             }
         }
 
@@ -99,40 +94,34 @@ namespace Tizen.Network.WiFi
         {
             add
             {
-                context.Post((x) =>
+                if (_connectionStateChanged == null)
                 {
-                    if (_connectionStateChanged == null)
+                    try
+                    {
+                        RegisterConnectionStateChangedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            RegisterConnectionStateChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on adding ConnectionStateChanged\n" + e);
-                            return;
-                        }
+                        Log.Error(Globals.LogTag, "Exception on adding ConnectionStateChanged\n" + e);
+                        return;
                     }
-                    _connectionStateChanged += value;
-                }, null);
+                }
+                _connectionStateChanged += value;
             }
             remove
             {
-                context.Post((x) =>
+                _connectionStateChanged -= value;
+                if (_connectionStateChanged == null)
                 {
-                    _connectionStateChanged -= value;
-                    if (_connectionStateChanged == null)
+                    try
+                    {
+                        UnregisterConnectionStateChangedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            UnregisterConnectionStateChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on removing ConnectionStateChanged\n" + e);
-                        }
+                        Log.Error(Globals.LogTag, "Exception on removing ConnectionStateChanged\n" + e);
                     }
-                }, null);
+                }
             }
         }
 
@@ -140,40 +129,34 @@ namespace Tizen.Network.WiFi
         {
             add
             {
-                context.Post((x) =>
+                if (_rssiLevelChanged == null)
                 {
-                    if (_rssiLevelChanged == null)
+                    try
                     {
-                        try
-                        {
-                            RegisterRssiLevelChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on adding RssiLevelChanged\n" + e);
-                            return;
-                        }
+                        RegisterRssiLevelChangedEvent();
                     }
-                    _rssiLevelChanged += value;
-                }, null);
+                    catch (Exception e)
+                    {
+                        Log.Error(Globals.LogTag, "Exception on adding RssiLevelChanged\n" + e);
+                        return;
+                    }
+                }
+                _rssiLevelChanged += value;
             }
             remove
             {
-                context.Post((x) =>
+                _rssiLevelChanged -= value;
+                if (_rssiLevelChanged == null)
                 {
-                    _rssiLevelChanged -= value;
-                    if (_rssiLevelChanged == null)
+                    try
                     {
-                        try
-                        {
-                            UnregisterRssiLevelChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on removing RssiLevelChanged\n" + e);
-                        }
+                        UnregisterRssiLevelChangedEvent();
                     }
-                }, null);
+                    catch (Exception e)
+                    {
+                        Log.Error(Globals.LogTag, "Exception on removing RssiLevelChanged\n" + e);
+                    }
+                }
             }
         }
 
@@ -181,40 +164,34 @@ namespace Tizen.Network.WiFi
         {
             add
             {
-                context.Post((x) =>
+                if (_scanStateChanged == null)
                 {
-                    if (_scanStateChanged == null)
+                    try
+                    {
+                        RegisterScanStateChangedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            RegisterScanStateChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on adding ScanStateChanged\n" + e);
-                            return;
-                        }
+                        Log.Error(Globals.LogTag, "Exception on adding ScanStateChanged\n" + e);
+                        return;
                     }
-                    _scanStateChanged += value;
-                }, null);
+                }
+                _scanStateChanged += value;
             }
             remove
             {
-                context.Post((x) =>
+                _scanStateChanged -= value;
+                if (_scanStateChanged == null)
                 {
-                    _scanStateChanged -= value;
-                    if (_scanStateChanged == null)
+                    try
+                    {
+                        UnregisterScanStateChangedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            UnregisterScanStateChangedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on removing ScanStateChanged\n" + e);
-                        }
+                        Log.Error(Globals.LogTag, "Exception on removing ScanStateChanged\n" + e);
                     }
-                }, null);
+                }
             }
         }
 
@@ -222,40 +199,34 @@ namespace Tizen.Network.WiFi
         {
             add
             {
-                context.Post((x) =>
+                if (_backgroundScanFinished == null)
                 {
-                    if (_backgroundScanFinished == null)
+                    try
+                    {
+                        RegisterBackgroundScanFinishedEvent();
+                    }
+                    catch (Exception e)
                     {
-                        try
-                        {
-                            RegisterBackgroundScanFinishedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on adding BackgroundScanFinished\n" + e);
-                            return;
-                        }
+                        Log.Error(Globals.LogTag, "Exception on adding BackgroundScanFinished\n" + e);
+                        return;
                     }
-                    _backgroundScanFinished += value;
-                }, null);
+                }
+                _backgroundScanFinished += value;
             }
             remove
             {
-                context.Post((x) =>
+                _backgroundScanFinished -= value;
+                if (_backgroundScanFinished == null)
                 {
-                    _backgroundScanFinished -= value;
-                    if (_backgroundScanFinished == null)
+                    try
                     {
-                        try
-                        {
-                            UnregisterBackgroundScanFinishedEvent();
-                        }
-                        catch (Exception e)
-                        {
-                            Log.Error(Globals.LogTag, "Exception on removing BackgroundScanFinished\n" + e);
-                        }
+                        UnregisterBackgroundScanFinishedEvent();
                     }
-                }, null);
+                    catch (Exception e)
+                    {
+                        Log.Error(Globals.LogTag, "Exception on removing BackgroundScanFinished\n" + e);
+                    }
+                }
             }
         }