diff --git a/src/csharp/Meadow/MeadowDeployer.cs b/src/csharp/Meadow/MeadowDeployer.cs index 616469a..236b6c0 100644 --- a/src/csharp/Meadow/MeadowDeployer.cs +++ b/src/csharp/Meadow/MeadowDeployer.cs @@ -48,19 +48,15 @@ public async void Dispose() } } - public async Task Deploy(string folder, int debugPort = -1) + public async Task Deploy(string folder, bool isDebugging) { - var isDebugging = debugPort > 1000; - - await Task.Run(async () => - { if (meadowConnection != null) { meadowConnection.FileWriteProgress -= MeadowConnection_DeploymentProgress; meadowConnection.DeviceMessageReceived -= MeadowConnection_DeviceMessageReceived; } - meadowConnection = await MeadowConnectionManager.GetConnectionForRoute(PortName); + meadowConnection = new MeadowConnectionManager(new SettingsManager()).GetConnectionForRoute(PortName); meadowConnection.FileWriteProgress += MeadowConnection_DeploymentProgress; meadowConnection.DeviceMessageReceived += MeadowConnection_DeviceMessageReceived; @@ -106,15 +102,7 @@ await Task.Run(async () => { meadowConnection.FileWriteProgress -= MeadowConnection_DeploymentProgress; } - }); - - // Debugger only returns when session is done - if (isDebugging) - { - Logger.LogInformation("Debugging application..."); - return await meadowConnection?.StartDebuggingSession(debugPort, Logger, CancelToken); - } - return null; + return meadowConnection; } private async void MeadowConnection_DeviceMessageReceived(object sender, (string message, string source) e) diff --git a/src/csharp/MonoDebugSession.cs b/src/csharp/MonoDebugSession.cs index 40d0625..9ce5dfd 100644 --- a/src/csharp/MonoDebugSession.cs +++ b/src/csharp/MonoDebugSession.cs @@ -219,18 +219,23 @@ public override async void Launch(Response response, dynamic args) try { var logger = new DebugSessionLogger(l => Log(l)); + + var isDebugging = launchOptions.DebugPort > 1024; // DEPLOY meadowDeployer = new MeadowDeployer(this, logger, launchOptions.Serial, ctsDeployMeadow.Token); - meadowDebuggingServer = await meadowDeployer.Deploy(fullOutputPath, launchOptions.DebugPort); + var meadowConnection = await meadowDeployer.Deploy(fullOutputPath, isDebugging); - if (meadowDebuggingServer != null) + if (isDebugging) { + var meadowDebuggingServerTask = meadowConnection.StartDebuggingSession(launchOptions.DebugPort, logger, ctsDeployMeadow.Token); + _attachMode = true; Log($"Connecting to debugger: {address}:{launchOptions.DebugPort}"); Connect(IPAddress.Loopback, launchOptions.DebugPort); + await meadowDebuggingServerTask; } SendResponse(response);