royben
Topic Author
Posts: 1
Joined: 20 Apr 2019, 09:17

WPF dispatcher replacement and multi-threading

20 Apr 2019, 18:23

Hello Noesis team,

I have been developing C#/WPF applications for years and like you, I like it's architecture but not the performance.
I am very excited about your application framework and trying to figure out if I can actually manage to build a full desktop application using it (no gaming).

I had some success in starting a small demo application but I feel like I have some issues with porting my current understanding of WPF and could not find proper documentation that can answer my questions.

1. WPF allows only one rendering thread. What is the rendering modal that your application framework uses? Can I optimize it by using more than a single rendering thread?
2. How do I invoke a method on the UI thread? What is the replacement for Dispatcher.BeginInvoke()?
3. What is the frame rate of the application? Can I control it ?
4. Can I force the application to render the visual tree at a specific moment ? (Push frame in WPF)
5. I could not make the DataGrid work. Is there no DataGrid in Noesis ?
6. Can I host an instance of Noesis as a control inside WPF?

Thanks!

Tags:
 
User avatar
jsantos
Site Admin
Posts: 2559
Joined: 20 Jan 2012, 17:18
Contact:

Re: WPF dispatcher replacement and multi-threading

22 Apr 2019, 16:35

Hi Roben,

Noesis is a bit different to WPF. It was designed to be extremely configurable and integrated in a non-intrusive way into your application. So, the core library is agnostic about platform details like renderer, threads, inputs, windows. We provide a layer, the Application Framework, that's more similar to WPF. We use that layer in all our samples. You can find more information about these differences in the NoesisGUI and WPF/UWP guide.

1. Yes, you can use more than one thread as explained in the Rendering Architecture tutorial.
2. You need to manage that yourself.
3. You manually pump frames. So you have all the control.
4. Yes
5. DataGrid is not implemented in Noesis. Could you please report about it?
6. Probably, but I am not sure if any client tried that. I think that using render to texture should work.

Thanks!
 
stonstad
Posts: 98
Joined: 06 Jun 2016, 18:14

Re: WPF dispatcher replacement and multi-threading

08 May 2019, 22:40

My app is threaded and performs work on and off the Unity main render thread. After asynchronous work... if I need to do something back on the Unity main render thread I use this class that I made. It queues up work for the next scripting frame update. Invocation is similar to WPF/UWP.

1. Attach script to game object.
2. Invoke via UnityDispatcher.Instance.Invoke(() => UnityFoo());

Enjoy!
   /// <summary>
    /// Thread dispatcher for Unity main render thread.
    /// </summary>
    public class UnityDispatcher : MonoBehaviour
    {
        private static UnityDispatcher _Instance = null;
        private ConcurrentQueue<Action> _ExecutionQueue = new ConcurrentQueue<Action>();

        public static UnityDispatcher Instance
        {
            get
            {
                if (_Instance == null)
                    throw new Exception("UnityDispatcher must be initialized before it may be used.  Has it been added to the scene hierarchy?");
                return _Instance;
            }
        }

        private void Awake()
        {
            if (_Instance == null)
                _Instance = this;
        }

        private void OnDestroy()
        {
            _Instance = null;
        }

        private void Update()
        {
            while (_ExecutionQueue.Count > 0)
            {
                Action action;
                if (_ExecutionQueue.TryDequeue(out action))
                    action.Invoke();
            }
        }

        private IEnumerator ActionWrapper(Action action)
        {
            action();
            yield return null;
        }

        public void Invoke(IEnumerator action)
        {
            _ExecutionQueue.Enqueue(() => StartCoroutine(action));
        }

        public void Invoke(Action action)
        {
            Invoke(ActionWrapper(action));
        }

        public static bool Exists()
        {
            return _Instance != null;
        }
    }
 
User avatar
sfernandez
Site Admin
Posts: 1624
Joined: 22 Dec 2011, 19:20

Re: WPF dispatcher replacement and multi-threading

11 May 2019, 18:32

Thanks for sharing this with the community :)

Who is online

Users browsing this forum: Bing [Bot] and 4 guests