-4

I am developing a system that is based on WPF. the UI need to let user compi and process. There is a function inside,Ability to perform user compilation So I can't control the user if user need to import third party dll I use a Thread to implement this function.

But now there is a problem, if the user calls the window inside the dll, the windows will freezes.

Main

    int main()
    {
        Thread th = new Thread(thread);
        th.Start();
    }

    void thread()
    {
        LoadLibrary("C:\\123\windows.dll");
        StartTest(dll_windows);
    }

DLL

    public static dll_windows()
    {
        ShowWindow();
    }
劉紘睿
  • 13
  • 2
  • Possible duplicate of [How do I update the GUI from another thread?](https://stackoverflow.com/questions/661561/how-do-i-update-the-gui-from-another-thread) –  Mar 27 '19 at 06:40

1 Answers1

1

In most, if not all frameworks I have seen across many languages, UI elements must be created on the UI thread. Creating them from another thread will lead to all kinds of problems.

Although you did not say what framework you use, I'm willing to bet it also goes for your framework. All your UI elements must be created from the UI thread.

Do work on the other thread, signal when it's done and then create the UI from the UI thread.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • 1
    _"Creating them from another thread will lead to all kinds of `problems`"_ - very true. There's a nice article on Oracle which _delves_ into it (pun intended): _[Multithreaded toolkits: A failed dream? Blog](https://community.oracle.com/blogs/kgh/2004/10/19/multithreaded-toolkits-failed-dream)_ –  Mar 27 '19 at 07:51
  • thanks,I think about any windows process,I should be use UI thread to process. – 劉紘睿 Mar 27 '19 at 09:09
  • 1
    @nvoigt make that `all OSs` or rather `window managers`. – Panagiotis Kanavos Mar 27 '19 at 10:32