1

I'm building a monitor folders using FileSystemWatcher (in WPF), and need to show the changes of the folders in popups in System Tray. I am using the library "NotifyIcon" to this (https://visualstudiogallery.msdn.microsoft.com/aacbc77c-4ef6-456f-80b7-1f157c2909f7/) but when run the application when it passes through the routine instantiates the object, an error occurs. I've had this problem before and managed to solve with the dispatcher, but now I'm having this problem in the instance of an object from an external library of visual studio (the NotifyIcon to the development of popups), I do not know how to solve. I've read some answers here in the forum, but nothing that has to do with instances of objects. I can't post any images, because i don't have enough reputation, but' i'll post the code. Sorry if vague question, or if the text contains errors, my English is not very good. Any doubts about the question, please ask me. hugs ~

        private void On_Created(object sender, System.IO.FileSystemEventArgs e)
    {
        ShowChanges(e.ChangeType, e.Name);
        Thread criacao = new Thread(new ThreadStart(NotifyCreated));
        criacao.SetApartmentState(ApartmentState.STA);
        criacao.Start();
    }

    private void NotifyCreated()
    {
        //the error occours here\/
        TaskbarIcon NotificaCriacao = new TaskbarIcon();
        string titulo = "Notificação de Ocorrencia";
        string ocorrencia = "Ocorrencia";
        NotificaCriacao.ShowBalloonTip(titulo, ocorrencia, BalloonIcon.Error);
    }
Ferboni
  • 11
  • 1
  • Is the `Exception` thrown on the `NotificaCriacao.ShowBalloonTip` call? – toadflakz Feb 23 '15 at 12:46
  • The __Related__ column contains about 10 duplicates, which one didn't answer your question? – H H Feb 23 '15 at 13:04
  • This is a common problem. It looks like you're trying to update the UI from a different thread. It'd probably be best to look in the related section as @HenkHolterman eloquently put it. – Mike Eason Feb 23 '15 at 13:05
  • @toadflakz The exception points to the line "TaskbarIcon NotificaCriacao = new TaskbarIcon ();" – Ferboni Feb 23 '15 at 14:02
  • As I said, this error have occurred to me before, but in other cases. This time the error is occurring in the instance of the object, like I can not instantiate the object in this method, because it belongs to another thread. In no topics refer to this error in an instance object. – Ferboni Feb 23 '15 at 14:06
  • Perhaps the answer is there, in the topics, but I'm new in C # and can not be understood. Can you help me? – Ferboni Feb 23 '15 at 14:09
  • The simple answer here: do not use a Thread. – H H Feb 23 '15 at 14:43
  • If I do not use the thread he's still another error saying that at different threads and that the type of form should STA, or something. So I used the "criacao.SetApartmentState (ApartmentState.STA);" – Ferboni Feb 23 '15 at 14:50
  • Then back up to the original problem, and research "WPF TaskbarIcon STA-Thread" – H H Feb 23 '15 at 18:17
  • The only way I found to solve it that way. – Ferboni Feb 24 '15 at 11:17

0 Answers0