How to execute code in the GUI Thread?

前端 未结 6 1093
我在风中等你
我在风中等你 2021-01-12 03:56

I have a FileSystemWatcher that react on the Changed event.

I want to open the file, read its content display it in a textbox and hide the popup that has been create

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 04:16

    To execute the extendedNotifyIcon_OnHideWindow method on the GUI thread use the Dispatcher as you did to show it.

    Thread threadToClosePopup = new Thread(new ThreadStart((Action)delegate() { 
      Thread.Sleep(1000); 
      txtLog.Dispatcher.Invoke(
        DispatcherPriority.Normal,
        (Action)() => extendedNotifyIcon_OnHideWindow());
    }));
    

提交回复
热议问题