4

Normally, UI controls must be used on the UI thread only. If you want to use a UI object from any other thread you usually have to invoke Control.Invoke. NotifyIcon does not have such a method.

What's the right way to do something with a NotifyIcon from a background thread?

For example, is the following legal? What's a legal alternative?

Task.Run(() => { notifyIcon.Visible = true; });
usr
  • 168,620
  • 35
  • 240
  • 369
  • [This question](http://stackoverflow.com/questions/10718369/displaying-wpf-notifyicon-on-a-separate-thread) might help. – Jashaszun Aug 07 '14 at 18:05
  • Maybe, pretty doubtful, the underlying Shell_NotifyIcon() function doesn't promise anything and shell functions are generally not thread-safe. Doing it right [isn't that difficult](http://stackoverflow.com/a/21684059/17034). – Hans Passant Aug 07 '14 at 19:00
  • @HansPassant That answer helps. I could create the icon on an existing UI thread, capture the synchronization context and post to that context at any point in time later. – usr Aug 07 '14 at 19:11

0 Answers0