아래 교착이 발생하는 코드입니다
코드 맥락상 교착이 발생할만한 부분이 없는 것 같은데 왜 교착이 발생하는 걸까요?
MainLoginForm.activeNumber 정적 필드를 제거하니 코드가 정상적으로 호출되긴 하는데
MainLoginForm.activeNumber 때문은 아닌 것 같아서요
안내해 주시면 정말 감사하겠습니다
MainForm.cs
private bool isRunningHeartbeat;
private void MainForm_Load(object sender, EventArgs e)
{
Task.Run(() => HeartBeatSender.SendHeartbeat());
this.isRunningHeartbeat = true;
}
HeartBeatSender.cs
class HeartBeatSender
{
public static async void SendHeartbeat()
{
while (true)
{
try
{
Dictionary<string, string> body = Cipher.GetHeartbeatEncryptedData("kk", "KakaoMap", MainLoginForm.activeNumber);
HttpContent content = new FormUrlEncodedContent(body);
string result = await Client.PostAsync("
https://ckmauth.com/new/heartbeat", content);
WriteLine(Thread.CurrentThread.ManagedThreadId); // 호출 안 됨
}
catch (Exception ex)
{
// 예외로도 안 빠짐
MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
await Task.Delay(5000);
}
}
}
}
Cipher.cs
public static Dictionary<string, string> GetHeartbeatEncryptedData(string id, string programType, string activeNumber)
{
using (Aes aes = Aes.Create())
{
aes.KeySize = 128;
aes.IV = Encoding.UTF8.GetBytes("ckminitialvector");
aes.Key = Encoding.UTF8.GetBytes("ckminitialkeyckm");
return new Dictionary<string, string>()
{
{ "i1", EncryptStringToBase64_Aes(id, aes.Key, aes.IV) },
{ "i2", EncryptStringToBase64_Aes(programType, aes.Key, aes.IV) },
{ "i3", EncryptStringToBase64_Aes(activeNumber, aes.Key, aes.IV) },
};
}
}
Client.cs
public static async Task<string> PostAsync(string url, HttpContent paylaod)
{
try
{
using (HttpResponseMessage response = await client.PostAsync(url, paylaod)) // PostAsnyc 호출 후 교착 발생
{
WriteLine(Thread.CurrentThread.ManagedThreadId); // 여기부터 호출 안 됨
string result = await response.Content.ReadAsStringAsync();
return result;
}
}
catch (Exception ex)
{
// 예외로도 안 빠짐
MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
}
return null;
}
MainLoginForm.cs
partial class MainLoginForm : Form
{
public static string activeNumber = "2"
}
[최초 등록일: ]
[최종 수정일: 7/16/2024]