how to restart a exited global app

Apr 14, 2011 at 10:51 AM

Hi, experts. I encount  a problem.

I host a global dynamic external application in IAD and it starts successfully by the method DesktopService.CreateDynamicApplications().  But later the user may exit the application as a normal operation , or the application shut down by itself on error. (the process of the app is exited).

What I want to do is to restart the application whenever the user want. I tried to invoke DesktopService.CreateDynamicApplications() again but it cannot works, following my codes:

IHostedApplication app = this.DesktopService.AppHost.GetApplication(appName);

//following 2 lines I tried to remove the old app object but it doesn't works.

this.DesktopService.AppHost.UnloadDynamicApplication(app);
this.DesktopService.CloseDynamicApplication(appName);

//it return true, but no new process starts.
bool b=this.DesktopService.CreateDynamicApplication(appName);

//it return the original app object

app = this.DesktopService.AppHost.GetApplication(appName);

When I looked into the assembly of Class Microsoft.Uii.Csr.ApplicationHost, I found the reason is that the static member initializedApps is still holding the old app object, so the initialize will not execute again.

public void InitializeApplications(IHostedApplication app)
{
    bool flag = false;
    if (this.IsGlobalApplication(app))
    {
        if (!Initialized(app))
        {
            flag = true;
            initializedApps.Add(app);
        }
    }
    else if (!this.InitializedNonGlobalApplication(app))
    {
        flag = true;
        this.initializedNonGlobalApps.Add(app);
    }
    if (flag)
    {

app.Initialize();
...
}

private static bool Initialized(IHostedApplication application)
{
    foreach (IHostedApplication application2 in initializedApps)
    {
        if (application2.ApplicationID == application.ApplicationID)
        {
            return true;
        }
    }
    return false;
}

I don't want to ask the user to restart the IAD to restart the app. Any good method to restart a exited global apps?

Thanks

Roland

 

Nov 6, 2012 at 3:15 AM

Hello hujiiori,

I was facing the same issue, found your post with no answers so I tried a few things.

The solution is simple, just call app.Initialize();

 

IHostedApplication hostedApp;
ApplicationHost currentAppHost = sessionManager.ActiveSession.AppHost;
hostedApp = currentAppHost.LoadDynamicApplication("YourAppName", false);
hostedApp.Initialize();
currentAppHost.ExecuteDefaultActions(hostedApp);
currentAppHost.NotifyContextChange(hostedApp);