I have an Background Service app which is created using .Net 6 and I want this service to run in edge client machines (Windows and Linux), the solution what I'm thinking of is to create an IoT Edge Module and run this in edge devices.
What are the possibilities to achieve this?
public class Worker : BackgroundService
{
private readonly ILogger\<Worker\> \_logger;
private readonly IBackgroundService \_backgroundService;
public Worker(ILogger<Worker> logger, IBackgroundService backgroundService)
{
_logger = logger;
_backgroundService= backgroundService;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
_backgroundService.Start();
await Task.Delay(Timeout.InfiniteTimeSpan, stoppingToken);
}
}
I have containerized the existing service and deployed the module in the Azure IoT Edge device, but the module runtime status shows Error and the logs shows nothing.

Below are the steps for setting up and debugging C/C# modules using Windows containers in the context of the Windows IoT Edge project:
File->New->Project.Azure IoT Edge (Windows amd64)underAzure IoTand provide a name for your project, then clickOK.Add a script to build and push module images. Update the script to push images to your own repository.
Update module.json to ensure the AzureIoTEdgeApp1 project can find the Dockerfile.windows-amd64.debug file.
Edit deployment.template.json to expose port 4022 for debugging.
Right-click AzureIotEdgeApp1 project, go to
Properties, and changeTarget ConfigurationtoDebug.If using a private registry like Azure Container Registry, use
docker logincommand to sign in.Input credentials for your registry in the
.envfile under Edge project.Generate deployment manifest
deployment.windows-amd64.debug.json.Code taken from git
Use Developer Command Prompt for VS to run
BuildAndPush.cmdscript to build and push the image.Deploy to IoT Edge Device:
Use Cloud Explorer to deploy the generated manifest to the IoT Edge device.
Manually start the remote debugger on the remote Windows machine using the
docker execcommand.In Visual Studio, go to
Debug->Attach to Process.Set
Connection TypetoRemote (no authentication).Set
Connection targetto[IP Address]:4022.Choose the process to debug:
IoTEdgeModule1.exeand “Attach to” to Native code.dotnet.exeand “Attach to” to Managed (CoreCLR).Set breakpoints and debug your C/C# module.
Make sure to replace placeholders like
[Your Registry Server],[Your Edge Module Container ID], and[IP Address]with appropriate values according to your setup. Also, ensure that you have the necessary permissions and configurations for Docker, Visual Studio, and your Azure services.