public override void Dispose()
 {
     base.Dispose();
     // stop listening
     DeploymentTargetsManager.DeviceListChanged -= OnExecutionTargetsChanged;
     DeploymentTargetsManager.StopPollingForDevices();
 }
        public async Task DeployApp(int debugPort, CancellationToken cancellationToken)
        {
            DeploymentTargetsManager.StopPollingForDevices();

            cleanedup = false;
            meadow?.Dispose();

            var target = this.Target as MeadowDeviceExecutionTarget;
            var device = await MeadowDeviceManager.GetMeadowForSerialPort(target.Port, logger : logger);

            meadow = new MeadowDeviceHelper(device, device.Logger);

            var fileNameExe = System.IO.Path.Combine(OutputDirectory, "App.dll");

            var debug = debugPort > 1000;

            await meadow.DeployAppAsync(fileNameExe, debug, cancellationToken);

            if (debug)
            {
                meadowDebugServer = await meadow.StartDebuggingSessionAsync(debugPort, cancellationToken);
            }
            else
            {
                // sleep until cancel since this is a normal deploy without debug
                while (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(1000);
                }

                Cleanup();
            }
        }
        // Note: see https://github.com/mhutch/MonoDevelop.AddinMaker/blob/eff386bfcce05918dbcfe190e9c2ed8513fe92ff/MonoDevelop.AddinMaker/AddinProjectFlavor.cs#L16 for better implementation

        // Called after the project finishes loading
        protected override void OnEndLoad()
        {
            base.OnEndLoad();

            Console.WriteLine("WLABS: OnEndLoad");

            // if the project is not a library
            // shouldn't this test if it's an executable?
            if (Project.CompileTarget != CompileTarget.Library)
            {
                Console.WriteLine("WLABS: Not a lib");

                DeploymentTargetsManager.DeviceListChanged += OnExecutionTargetsChanged;
                DeploymentTargetsManager.StartPollingForDevices();
            }
        }
        public void Cleanup()
        {
            if (cleanedup)
            {
                return;
            }

            meadowDebugServer?.StopListeningAsync();
            meadowDebugServer?.Dispose();
            meadowDebugServer = null;

            meadow?.Dispose();

            if (!cleanedup)
            {
                _ = DeploymentTargetsManager.StartPollingForDevices();
            }

            cleanedup = true;
        }