Windows 服务中截图运行到CopyFromScreen函数报错"句柄无效",在Winform程序中运行正常。 Google、百度了一下,有网友说是此程序不适合做成服务程序,未找到解决办法! 如图所示: 代码如下: public static Bitmap GetScreen() { int w = Screen.PrimaryScreen.Bounds.Width; int h = Screen.PrimaryScreen.Bounds.Height; Bitmap bitmap = new Bitmap(w, h); Graphics g = Graphics.FromImage(bitmap); try { //从指定的区域中复制图形,抓取屏幕中的图形区域 g.CopyFromScreen(Point.Empty, Point.Empty, new Size(w, h)); } catch (Exception err) { monitor.monitoring.ExecptionInfo(err.Message, err.Source, "monitor.ScreenShot"+monitor.monitoring.GetNetCardMacAddress(), "CutImage"); } return bitmap; }