Show notification from second thread

I have an attachment uploader, wich takes some attachments and sends them to another system via webservices.
My application has several modules (web, services, model, etc). Vaadin is in web, version 7.3.9.
To send the attachment to the other system I call a method in the services module, something like this:

[code]
public void sendToTheOtherSystem (final DataToSend dataToSend,
final AttachmentEventHandler handler,
final AttachmentErrorListener errorListener) throws WebServiceException
{
new Thread(new Runnable()
{
@Override
public void run()
{
List attachments = dataToSend.getAttachments();

      if (!attachments.isEmpty() && handler != null)
      {
         MyResponse response = sendAttachments(handler, attachments);

         if (response.hasErrors())
            errorListener.showError();
      }
  }

}).start();
}
[/code]I have it inside a new thread because I have a ProgressBar and I need to have the GUI thread free to update the progress in the bar. This is handled by AttachmentEventHandler.
If there is an error with the process I want to show a Notification. To do so I have the AttachmentErrorListener, which method showError() is implemented in in a class inside the web module.
From there I was expecting to do something like:

@Override public void showError() { Notification notification = new Notification("Title", "Description", Notification.Type.ERROR_MESSAGE); notification.show(Page.getCurrent()); } This doesn’t work, the notification is not shown. As we are doing this from another thread I though I could solve it by having the code inside UI.getCurrent().access, like this:

@Override 
public void showError() 
{
   UI.getCurrent().access(new Runnable() {
      @Override 
      public void run() 
      {
         Notification notification = new Notification("Title", "Description", Notification.Type.ERROR_MESSAGE);
         notification.show(Page.getCurrent());
      }
   });
}

But this is even worse because it makes the page freeze completely.
How can I show a Notification when something goes wrong and have a ProgressBar as well?

Thanks

I’ve found something that maybe could be my solution?
ErrorHandlingRunnable()
. I don’t really know how to use it or if it would really solve my problem. Somebody who can help?

The last way you present is the correct one; when running code from outside a request, you need to wrap it in a Runnable. Then the issue becomes the UI freezing; probably some incorrect lock handling somewhere. What server are you running on, and what Vaadin version are you using?

Oh, and BTW, UI.getCurrent() will not work from outside a Vaadin context; you need to get the reference during the initial call and save it somewhere during the processing.