Skip to content

Latest commit

 

History

History
103 lines (84 loc) · 4.33 KB

File metadata and controls

103 lines (84 loc) · 4.33 KB

PX1054

This document describes the PX1054 diagnostic.

Summary

Code Short Description Type Code Fix
PX1054 Long-running operations cannot be started during the PXGraph and PXGraphExtension initialization. Error Unavailable

Diagnostic Description

Long-running operation cannot be started during the PXGraph and PXGraphExtension initialization. Long-running operations are started by the following APIs:

  • The PXLongOperation.StartOperation methods
  • The ILongOperationManager.StartOperation, ILongOperationManager.StartAsyncOperation, and ILongOperationManager.Await methods
  • The IGraphLongOperationManager.StartOperation and IGraphLongOperationManager.StartAsyncOperation methods

The following code elements are considered to be a part of the initialization logic:

  • The PXGraph and PXGraphExtension constructors
  • The Initialize method overridden in PXGraphExtension
  • The Initialize method of PXGraph that implements the PX.Data.DependencyInjection.IGraphWithInitialization interface
  • The Configure method overridden in PXGraph and PXGraphExtension
  • The IsActive and IsActiveForGraph<TGraph> static methods in PXGraphExtension

To fix the issue, you remove from the initialization logic the invocation of a long-running operation and rework the related business logic.

Example of Incorrect Code

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();
	}
}

Related Articles