Under a certain condition I need to prevent the user from closing both the project they have opened and the Pro application (essentially disabling the X button in the upper right corner). I have subscribed to ProjectClosingEvent and set args.Cancel to true. The project still closes while Pro does not. What should be done to keep the project open? Thanks.
public Module1()
{
ProjectClosingEvent.Subscribe(OnProjectClosing);
}
private Task OnProjectClosing(ProjectClosingEventArgs args)
{
if (CanClosePro == false)
{
args.Cancel = true;
return Task.FromResult(0);
}
else
{
return Task.CompletedTask;
}
}
Hi Alex,
Have you set the autoload DAML attribute to true to load your module? I am wondering if the event subscription kicked in. One way to confirm can be to put System diagnostic messages in your OnProjectClosing event handler. I use that to test events.
I was able to disable Project closing with your code.
Thanks
Uma
if (CanClosePro == false)
{
args.Cancel = true;
System.Diagnostics.Debug.WriteLine(..
return Task.FromResult(0);
}
Thanks Uma, the code does work as expected, sorry for the confusion. There was another OnProjectClosing event handler in the solution which led to the unexpected results.