1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00

Send only single command to MPD.

This commit is contained in:
glucaci 2016-12-20 10:42:53 +01:00
parent 7068ac9db0
commit fe55423be2

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LibMpc namespace LibMpc
@ -14,6 +14,7 @@ namespace LibMpc
{ {
private static readonly Regex STATUS_AUDIO_REGEX = new Regex("^(?<sampleRate>[0-9]*):(?<bits>[0-9]*):(?<channels>[0-9]*)$"); private static readonly Regex STATUS_AUDIO_REGEX = new Regex("^(?<sampleRate>[0-9]*):(?<bits>[0-9]*):(?<channels>[0-9]*)$");
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private readonly IPEndPoint _server; private readonly IPEndPoint _server;
private MpcConnection _connection; private MpcConnection _connection;
@ -54,9 +55,15 @@ namespace LibMpc
public async Task<IMpdMessage<T>> SendAsync<T>(IMpcCommand<T> command) public async Task<IMpdMessage<T>> SendAsync<T>(IMpcCommand<T> command)
{ {
var mpdMessage = await _connection.SendAsync(command); await _semaphore.WaitAsync();
try
return mpdMessage; {
return await _connection.SendAsync(command);
}
finally
{
_semaphore.Release();
}
} }
/* /*