1. 조건 재시작 및 프로그램 종료 Thread 수정

This commit is contained in:
USER002
2024-06-14 14:47:51 +09:00
parent fcc92807e6
commit 6d788f795a
7 changed files with 294 additions and 360 deletions

View File

@@ -23,6 +23,8 @@ namespace BitgetAPI.WebService
public class WebConnection
{
public Thread th_PingTimer {get; set;} = null;
public bool Is_th_webSocketThread { get; set; } = false;
public ClientWebSocket webSocket { get; set; } = null;
public static object SendWebServer(CommonProperty.ExchangeWebReqType exchangeWebReqType, string url = "",
MarketCandleDataList marketCandleDataList = null, CommonProperty.MCandleTimeType interval = MCandleTimeType.M1,
@@ -279,7 +281,7 @@ namespace BitgetAPI.WebService
CommonProperty commonProperty = CommonProperty.Instance;
ClientWebSocket webSocket = new ClientWebSocket();
webSocket = new ClientWebSocket();
string WebSocketUrl = "wss://ws.bitget.com/v2/ws/public";
string message = "";
@@ -304,6 +306,7 @@ namespace BitgetAPI.WebService
// 데이터 수신을 위한 반복문 시작
while (webSocket.State == WebSocketState.Open)
{
//Thread.Sleep(100);
byte[] buffer = new byte[1024];
@@ -371,6 +374,7 @@ namespace BitgetAPI.WebService
// 마지막 시간 데이터 가져오기
var lastCandleData = lastCandleData_Edit.Find(j=>j.Argument == lastCandleData_Edit.Max(i => i.Argument));
if (lastCandleData == null) return;
// 업데이트 or 추가
bool updateFlag = true;
@@ -573,15 +577,37 @@ namespace BitgetAPI.WebService
}
finally
{
//if (webSocket.State == WebSocketState.Open)
//await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "WebSocket 연결 종료", CancellationToken.None);
webSocket.Dispose();
closeWebSocket();
// 웹소켓 재귀
BitGetWebSocektStart(bitgetWebSocketType, dic);
if (Is_th_webSocketThread)
{
BitGetWebSocektStart(bitgetWebSocketType, dic);
}
}
}
// 웹소켓 종료
public async void closeWebSocket()
{
if (webSocket != null)
{
if (webSocket.State == WebSocketState.Open)
{
if (th_PingTimer != null)
{
th_PingTimer.Abort();
th_PingTimer = null;
}
await webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "WebSocket 연결 종료", CancellationToken.None);
}
webSocket.Dispose();
}
}
// Ping 테스트 (25초), 30초에 한번 응답 확인 필요
public static async void ContinuePing(ClientWebSocket webSocket)
{