use Task.Delay instead of Thread.Sleep

pull/3895/head
2dust 2 years ago
parent abe484b0df
commit 566f056149

@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PacLib; namespace PacLib;
@ -50,7 +49,7 @@ public class PacHandler
_tcpListener = TcpListener.Create(_pacPort); _tcpListener = TcpListener.Create(_pacPort);
_isRunning = true; _isRunning = true;
_tcpListener.Start(); _tcpListener.Start();
Task.Factory.StartNew(() => Task.Factory.StartNew(async () =>
{ {
while (_isRunning) while (_isRunning)
{ {
@ -58,12 +57,12 @@ public class PacHandler
{ {
if (!_tcpListener.Pending()) if (!_tcpListener.Pending())
{ {
Thread.Sleep(10); await Task.Delay(10);
continue; continue;
} }
var client = _tcpListener.AcceptTcpClient(); var client = _tcpListener.AcceptTcpClient();
Task.Run(() => await Task.Run(() =>
{ {
var stream = client.GetStream(); var stream = client.GetStream();
var sb = new StringBuilder(); var sb = new StringBuilder();

Loading…
Cancel
Save