+/*
+ * Copyright(c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
-using System.Reflection;
using System;
-using System.Runtime.InteropServices;
using System.Collections.Generic;
-using Tizen.NUI.BaseComponents;
+using System.Threading;
namespace Tizen.NUI
{
/// </summary>
internal sealed class Registry
{
+ private static readonly Registry registry = new Registry();
+
/// <summary>
- /// The registry is a singleton.
+ /// static initialization singleton
/// </summary>
- private static Registry instance = null;
+ internal static Registry Instance
+ {
+ get { return registry; }
+ }
/// <summary>
/// Given a C++ object, the dictionary allows us to find which C# object it belongs to.
/// <param name="baseHandle">The instance of BaseHandle (C# base class).</param>
internal static void Register(BaseHandle baseHandle)
{
+ if(savedApplicationThread?.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)
+ {
+ throw new global::System.ApplicationException("NUI object is attempt to be created in another thread. It should be created in main thread only!");
+ }
+
// We store a pointer to the RefObject for the control
RefObject refObj = baseHandle.GetObjectPtr();
IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
return;
}
- private static Registry Instance
- {
- get
- {
- if (instance == null)
- {
- instance = new Registry();
- }
- return instance;
- }
- }
-
internal static BaseHandle GetManagedBaseHandleFromNativePtr(BaseHandle baseHandle)
{
RefObject refObj = baseHandle.GetObjectPtr();
}
}
+ private static Thread savedApplicationThread;
+ internal Thread SavedApplicationThread
+ {
+ get
+ {
+ return savedApplicationThread;
+ }
+ set
+ {
+ savedApplicationThread = value;
+ }
+ }
+
}
}
using System;
using System.ComponentModel;
+using System.Threading;
using Tizen.Applications;
using Tizen.Applications.CoreBackend;
/// <since_tizen> 3 </since_tizen>
public NUIApplication() : base(new NUICoreBackend())
{
+ Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
{
+ Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
{
+ Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
}
/// <summary>
pointLabel.PointSize = 32.0f;
window.Add(pointLabel);
+ Timer timer = new Timer(1000);
+
Task.Factory.StartNew(() =>
{
try
{
- TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
- ellipsis.Size2D = new Size2D(100, 100);
- ellipsis.Position2D = new Position2D(10, 250);
- ellipsis.PointSize = 20.0f;
- ellipsis.Ellipsis = true;
- window.Add(ellipsis);
+ Timer timer_in_another_thread = new Timer(1000);
+
+ TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
+ ellipsis.Size2D = new Size2D(100, 100);
+ ellipsis.Position2D = new Position2D(10, 250);
+ ellipsis.PointSize = 20.0f;
+ ellipsis.Ellipsis = true;
+ window.Add(ellipsis);
}
catch (Exception e)
{