private void AppendPacketLogItems(string orientation, byte[] payload) { PacketLogLVI pl = new PacketLogLVI() { Index = (Frm.lv_packet_log.Items.Count + 1).ToString(), Orientation = orientation, CaptureTime = DateTime.Now.ToString(), PayloadLen = payload.Length.ToString(), PayloadData = payload.HexDump(), Tag = new PacketAnalyzer() { HexPayload = payload.HexDump() } }; if (orientation == "Send") { pl.SrcIp = $"{MatchedSrcIp}:{MatchedSrcPort}"; pl.DstIp = $"{MatchedDstIp}:{MatchedDstPort}"; } else { pl.SrcIp = $"{MatchedDstIp}:{MatchedDstPort}"; pl.DstIp = $"{MatchedSrcIp}:{MatchedSrcPort}"; } Frm.ThreadSafeUpdate(() => { ListViewItem lv = pl.BuildLVI(); lv.ForeColor = orientation == "Send" ? Color.Red : Color.Blue; Frm.lv_packet_log.Items.Add(lv); }); }
private void Btn_stop_httpserver_Click(object sender, EventArgs e) { new Thread(() => { if (HttpServer != null && HttpServer.SocketChannel.Open == true) { Frm.ThreadSafeUpdate(() => Frm.btn_start_httpserver.Enabled = false); Frm.ThreadSafeUpdate(() => Frm.btn_stop_httpserver.Enabled = false); Frm.ThreadSafeUpdate(() => Frm.btn_stop_httpserver.Text = "关闭中"); if (HttpServer.Stop()) { HttpServerLog("HTTP服务器关闭成功"); Frm.ThreadSafeUpdate(() => Frm.btn_start_httpserver.Enabled = true); Frm.ThreadSafeUpdate(() => Frm.btn_stop_httpserver.Enabled = true); Frm.ThreadSafeUpdate(() => Frm.btn_stop_httpserver.Text = "关闭"); } } }).Start(); }
public static void HttpServerLog(string text) { string output = string.Format("{0} {1}{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), text, Environment.NewLine); Frm.ThreadSafeUpdate(() => Frm.richTextBox_httpserver_log.AppendText(output)); }