title: Is there a way to have a OnReceiveLocalNotification (TNotificationCenter) working even after the app close?
body: <p>My app has some tasks that need to run in background. I use the task scheduler to run the app when a task is needed and the app close it self when the task is finished. So far, so good.</p>
  
  <p>The tasks could take some time to finish so I send notifications to action center in the begining and in the end of the task. For the first one I have no problems, but in the second notification I want to open a log file when the user click in it. </p>
  
  <p>The action center show both of notifications but the log file does not open when notification is clicked. I guess it's because the app already close.</p>
  
  <p>So far I tried the following.</p>
  
  <pre><code>uses
    System.SysUtils, System.Classes, System.Notification,
    System.Generics.Collections;
  
  type
    TActionCenter = class(TDataModule)
      NotificationCenter: TNotificationCenter;
      procedure NotificationCenterReceiveLocalNotification(Sender: TObject;
        ANotification: TNotification);
    strict private
      FNotifications: TDictionary&lt;string, TOnReceiveLocalNotification&gt;;
    public
      class procedure AppRegister(const ACompanyName: string);
      procedure AfterConstruction; override;
      procedure BeforeDestruction; override;
      procedure SendNotification(const ATitle, AMessage: string); overload;
      procedure SendNotification(const ATitle, AMessage: string; AOnClick: TOnReceiveLocalNotification); overload;
    end;
  
  var
    _ActionCenter: TActionCenter;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>uses
    System.Hash, System.Win.Registry, Winapi.Windows;
  
  procedure TActionCenter.AfterConstruction;
  begin
    inherited;
    FNotifications := TDictionary&lt;string, TOnReceiveLocalNotification&gt;.Create;
  end;
  
  class procedure TActionCenter.AppRegister(const ACompanyName: string);
  const
    ActionCenterKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\';
  var
    ApplicationKey: string;
    Registry: TRegistry;
  begin
    ApplicationKey := ACompanyName + '.DesktopToasts.' + THashBobJenkins.GetHashString(ParamStr(0));
    Registry := TRegistry.Create;
    try
      Registry.RootKey := HKEY_CURRENT_USER;
      if not Registry.KeyExists(ActionCenterKey + ApplicationKey) then
      begin
        Registry.Access := KEY_WRITE;
        if Registry.OpenKey(ActionCenterKey + ApplicationKey, True) then
          Registry.WriteInteger('ShowInActionCenter', 1);
      end;
    finally
      Registry.Free;
    end;
  end;
  
  procedure TActionCenter.BeforeDestruction;
  begin
    inherited;
    FNotifications.Free;
  end;
  
  procedure TActionCenter.NotificationCenterReceiveLocalNotification(
    Sender: TObject; ANotification: TNotification);
  var
    Pair: TPair&lt;string, TOnReceiveLocalNotification&gt;;
  begin
    Pair := FNotifications.ExtractPair(ANotification.Name);
    if Assigned(Pair.Value) then
      Pair.Value(Sender, ANotification);
  end;
  
  procedure TActionCenter.SendNotification(const ATitle, AMessage: string);
  begin
    SendNotification(ATitle, AMessage, nil);
  end;
  
  procedure TActionCenter.SendNotification(const ATitle, AMessage: string;
    AOnClick: TOnReceiveLocalNotification);
  var
    Notification: TNotification;
  begin
    Notification := NotificationCenter.CreateNotification;
    try
      Notification.Name := TGUID.NewGuid.ToString;
      Notification.Title := ATitle;
      Notification.AlertBody := AMessage;
      FNotifications.Add(Notification.Name, AOnClick);
      NotificationCenter.PresentNotification(Notification);
    finally
      Notification.Free;
    end;
  end;
  
  initialization
    TActionCenter.AppRegister('MyCompanyName');
    _ActionCenter := TActionCenter.Create(nil);
  
  finalization
    _ActionCenter.Free;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
    System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
    Vcl.StdCtrls, ActionCenter.Classes;
  
  type
    TMain = class(TForm)
      Send: TButton;
      procedure SendClick(Sender: TObject);
    strict private
      procedure NotificationClick1(ASender: TObject; ANotification: TNotification);
      procedure NotificationClick2(ASender: TObject; ANotification: TNotification);
      procedure NotificationClick3(ASender: TObject; ANotification: TNotification);
      procedure OpenLog(FileName: TFileName);
    end;
  </code></pre>
  
  <p>....</p>
  
  <pre><code>uses
    Winapi.ShellAPI;
  
  procedure TMain.NotificationClick1(ASender: TObject; ANotification: TNotification);
  begin
    OpenLog('C:\First.txt');
  end;
  
  procedure TMain.NotificationClick2(ASender: TObject; ANotification: TNotification);
  begin
    OpenLog('C:\Second.txt');
  end;
  
  procedure TMain.NotificationClick3(ASender: TObject; ANotification: TNotification);
  begin
    OpenLog('C:\Third.txt');
  end;
  
  procedure TMain.OpenLog(FileName: TFileName);
  var
    Handle: THandle;
  begin
    Handle := GetStdHandle(STD_INPUT_HANDLE);
    ShellExecute(Handle, nil, PChar(FileName), nil, nil, SW_SHOWNORMAL);
  end;
  </code></pre>
  
  <p>Is there a way to do this? Do a OnReceiveLocalNotification event that Works even after the app is close?</p>