我有一个简单的C#控制台应用程序附加到事件.我需要程序继续运行,以便它可以响应事件.什么是保持运行的正确方法?
这是我的申请:
using System; using NAudio.CoreAudioApi; namespace MaxVolume { class Program { private const float DesiredLevel = -15; private static MMDevice _device; static void Main(string[] args) { MMDeviceEnumerator mmde = new MMDeviceEnumerator(); _device = mmde.GetDefaultAudioEndpoint(DataFlow.Render,Role.Multimedia); _device.AudioEndpointVolume.MasterVolumeLevel = DesiredLevel; _device.AudioEndpointVolume.OnVolumeNotification += SetVolume; } static void SetVolume(AudioVolumeNotificationData data) { if (Math.Abs(data.MasterVolume - DesiredLevel) > 0.1) { _device.AudioEndpointVolume.MasterVolumeLevel = DesiredLevel; } } } }