refactor event to EventWrapper
This commit is contained in:
@@ -109,7 +109,7 @@ public class RunService(ILogger<RunService> logger, RoslynAnalysis roslynAnalysi
|
||||
GlobalEvents.Instance.StartedRunningProject.InvokeParallelFireAndForget();
|
||||
GlobalEvents.Instance.ProjectStartedRunning.InvokeParallelFireAndForget(project);
|
||||
}
|
||||
project.InvokeProjectStartedRunning();
|
||||
project.ProjectStartedRunning.InvokeParallelFireAndForget();
|
||||
await process.WaitForExitAsync().WaitAsync(project.RunningCancellationTokenSource.Token).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||
if (project.RunningCancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ public class RunService(ILogger<RunService> logger, RoslynAnalysis roslynAnalysi
|
||||
GlobalEvents.Instance.ProjectStoppedRunning.InvokeParallelFireAndForget(project);
|
||||
}
|
||||
|
||||
project.InvokeProjectStoppedRunning();
|
||||
project.ProjectStoppedRunning.InvokeParallelFireAndForget();
|
||||
|
||||
_logger.LogInformation("Process for project {ProjectName} has exited", project.Name);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis;
|
||||
using ObservableCollections;
|
||||
using SharpIDE.Application.Features.Analysis;
|
||||
using SharpIDE.Application.Features.Evaluation;
|
||||
using SharpIDE.Application.Features.Events;
|
||||
using Project = Microsoft.Build.Evaluation.Project;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
@@ -133,11 +134,9 @@ public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChi
|
||||
public bool OpenInRunPanel { get; set; }
|
||||
public Channel<byte[]>? RunningOutputChannel { get; set; }
|
||||
|
||||
public event Func<Task> ProjectStartedRunning = () => Task.CompletedTask;
|
||||
public void InvokeProjectStartedRunning() => ProjectStartedRunning.Invoke();
|
||||
public EventWrapper<Task> ProjectStartedRunning { get; } = new(() => Task.CompletedTask);
|
||||
public EventWrapper<Task> ProjectStoppedRunning { get; } = new(() => Task.CompletedTask);
|
||||
|
||||
public event Func<Task> ProjectStoppedRunning = () => Task.CompletedTask;
|
||||
public void InvokeProjectStoppedRunning() => ProjectStoppedRunning.Invoke();
|
||||
|
||||
public ObservableHashSet<SharpIdeDiagnostic> Diagnostics { get; internal set; } = [];
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public partial class RunMenuItem : HBoxContainer
|
||||
_stopButton.Pressed += OnStopButtonPressed;
|
||||
_debugButton = GetNode<Button>("DebugButton");
|
||||
_debugButton.Pressed += OnDebugButtonPressed;
|
||||
Project.ProjectStartedRunning += OnProjectStartedRunning;
|
||||
Project.ProjectStoppedRunning += OnProjectStoppedRunning;
|
||||
Project.ProjectStartedRunning.Subscribe(OnProjectStartedRunning);
|
||||
Project.ProjectStoppedRunning.Subscribe(OnProjectStoppedRunning);
|
||||
}
|
||||
|
||||
private async Task OnProjectStoppedRunning()
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Project.ProjectStartedRunning += OnProjectStartedRunning;
|
||||
Project.ProjectStartedRunning.Subscribe(OnProjectStartedRunning);
|
||||
// This event may/will be raised before the component is initialized, so we call OnProjectStartedRunning directly, for the first render.
|
||||
await OnProjectStartedRunning();
|
||||
}
|
||||
@@ -46,5 +46,5 @@
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose() => Project.ProjectStartedRunning -= OnProjectStartedRunning;
|
||||
public void Dispose() => Project.ProjectStartedRunning.Unsubscribe(OnProjectStartedRunning);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user