如何使SendMessage解除阻止?

时间:2015-09-20 09:13:03

标签: python winapi pywin32

我有这个脚本关闭显示器:

import win32api, win32con

print "start"
win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, 2)
print "end"
不打印

"end",脚本永远不会结束 当终端窗口保持打开时,这很烦人。

如何使SendMessage无阻塞?

1 个答案:

答案 0 :(得分:3)

您无法使public void SaveXml(int id, string xmlFileName) { // read your XML string xmlContent = File.ReadAllText(xmlFileName); // set up query string insertQuery = "INSERT INTO pages(BPMNID, XML) VALUES (@BPMNID, @XML)"; using (SqlConnection conn = new SqlConnection(-your-connection-string-here-)) using (SqlCommand cmd = new SqlCommand(insertQuery, conn)) { // define parameters cmd.Parameters.Add("@BPMNID", SqlDbType.Int).Value = id; cmd.Parameters.Add("@XML", SqlDbType.VarChar, -1).Value = xmlContent; // open connection, execute query, close connection conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } 无阻塞,因为基础Windows功能正在阻止。相反,您可以使用win32api.SendMessage(),它具有相同的签名:

win32api.PostMessage()