我有一个简单的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; } } } }
解决方法
原文地址:https://www.jb51.cc/csharp/100231.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。