This document describes the PX1054 diagnostic.
| Code | Short Description | Type | Code Fix |
|---|---|---|---|
| PX1054 | Long-running operations cannot be started during the PXGraph and PXGraphExtension initialization. |
Error | Unavailable |
Long-running operation cannot be started during the PXGraph and PXGraphExtension initialization. Long-running operations are started by the following APIs:
- The
PXLongOperation.StartOperationmethods - The
ILongOperationManager.StartOperation,ILongOperationManager.StartAsyncOperation, andILongOperationManager.Awaitmethods - The
IGraphLongOperationManager.StartOperationandIGraphLongOperationManager.StartAsyncOperationmethods
The following code elements are considered to be a part of the initialization logic:
- The
PXGraphandPXGraphExtensionconstructors - The
Initializemethod overridden inPXGraphExtension - The
Initializemethod ofPXGraphthat implements thePX.Data.DependencyInjection.IGraphWithInitializationinterface - The
Configuremethod overridden inPXGraphandPXGraphExtension - The
IsActiveandIsActiveForGraph<TGraph>static methods inPXGraphExtension
To fix the issue, you remove from the initialization logic the invocation of a long-running operation and rework the related business logic.
public class SMUserProcess : PXGraph<SMUserProcess>, PX.Data.DependencyInjection.IGraphWithInitialization
{
public SMUserProcess()
{
StartLongRun(); // The PX1054 error is displayed for this line.
}
private void StartLongRun()
{
PXLongOperation.StartOperation(this, () => Console.WriteLine("Long Operation has been started");
}
public void Initialize() =>
PXLongOperation.StartOperation(this, () => Console.WriteLine("Long Operation has been started"));
public override void Configure(PXScreenConfiguration graph)
{
base.Configure(graph);
PXLongOperation.StartOperation(this, () => Console.WriteLine("Long Operation has been started"));
}
}
public class SMAccessExt : PXGraphExtension<SMUserProcess>
{
public static bool IsActive()
{
PXLongOperation.StartOperation(Guid.NewGuid(), () => Console.WriteLine("Long Operation has been started"));
return PXAccess.FeatureInstalled<FeaturesSet.someFeature>();
}
public static bool IsActiveForGraph<TGraph>()
{
PXLongOperation.StartOperation(Guid.NewGuid(), () => Console.WriteLine("Long Operation has been started"));
return typeof(TGraph) == typeof(SMUserProcess);
}
public SMAccessExt()
{
PXLongOperation.StartOperation(Guid.NewGuid(), () => Console.WriteLine("Long Operation has been started"));
}
public override void Initialize()
{
Base.LongOperationManager.StartAsyncOperation(Base, async cToken =>
{
Console.WriteLine("Long Operation has been started");
await SyncUsersAsync(cToken);
});
}
public override void Configure(PXScreenConfiguration configuration)
{
base.Configure(configuration);
Base.LongOperationManager.Await(SyncUsersAsync, CancellationToken.None); // Starts long running operation
}
public static void SyncUsers(CancellationToken cancellation = default)
{
}
public static async Task SyncUsersAsync(CancellationToken cancellation = default)
{
await Task.Yield();
}
}