Prioritize display Notification

Hello
I have the following case, I have a button with a Download that download a file from a server.
In the class constructor I have:

StreamResource sr = getExcelStream ();
FileDownloader fileDownloader = new FileDownloader (sr);
fileDownloader.extend (btExcel);

getExcelStream () is:

private StreamResource getExcelStream () {
StreamResource.StreamSource source = new StreamResource.StreamSource () {
private static final long serialVersionUID = -1413114720868341991L;

        public InputStream getStream () {
         Notification notif = null;
         try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream ();
         
            String content = loadTable (true);
            if (content.isEmpty ()) {
             notif = null;
             UI.getCurrent (). MarkAsDirtyRecursive ();
              notif = new Notification (translator.getTranslation ("cosmsexportKO"), Type.ERROR_MESSAGE);
              notif.setDelayMsec (2000);
              notif.show (UI.getCurrent (). getPage ());
              UI.getCurrent (). MarkAsDirtyRecursive ();
              return null;
            }
            stream.write (Base64.decodeBase64 (content));
            InputStream input = new ByteArrayInputStream (stream.toByteArray ());
            return input;
           } catch (Exception e) {
             notif = null;
             UI.getCurrent (). MarkAsDirtyRecursive ();
             notif = new Notification (translator.getTranslation ("cosmsexportKO"), Type.ERROR_MESSAGE);
             notif.setDelayMsec (2000);
             notif.show (UI.getCurrent (). getPage ());
             UI.getCurrent (). MarkAsDirtyRecursive ();
             return null;
           }
        }
    };
  StreamResource resource = new StreamResource (source, "listacontratos.xls");
  return resource;

}

The code may be better, but it is not the case …
The problem is the following, I want it when I call the method: loadTable (true); is displayed a Notification that says that the file is being downloaded (raductor.getTranslation (“cosmsexportKO”), but the problem is that until it leaves the method getExcelStream () does not do it.
For more I have tried to put the code to display the message in the Button.ClickListener … put the markAsDirty … I have not managed to do it … Does anyone have any ideas?
Sorry for my poor english
Eduardo.

I think you should not need markAsDirty… here at all. So you can remove them.

Hi!!!
No, doesnt work… :frowning: I put markAsDirty because only display de notification after exit the method…

Thank you!!!