我想要获取所有可以截图的窗口,应用程序窗口。我正在尝试使用EnumWindows
.
public delegate bool CallBackPtr(IntPtr hwnd, int lParam);
[DllImport("user32.dll")]
private static extern int EnumWindows(CallBackPtr callPtr, int lPar);
public static List<IntPtr> EnumWindows()
{
var result = new List<IntPtr>();
EnumWindows(new User32.CallBackPtr((hwnd, lParam) =>
{
result.Add(hwnd);
return true;
}), 0);
return result;
}
Run Code Online (Sandbox Code Playgroud)
然而,这返回的 Windows 数量超出了我的预期,例如:
我只想获取 Windows,例如 Visual Studio、Skype、Explorer、Chrome...
我应该使用其他方法吗?或者我如何检查它是否是我想要抓取的窗口?
我想将数据写入现有的Excel文件。 该文件有sheet1,我想在sheet2上写,然后保存。问题是,每次保存时,它将创建一个新的excel文件并覆盖现有文件。保存时保留旧数据的任何帮助。
我有以下功能
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("csharp.net-informations.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
MessageBox.Show(xlWorkSheet.get_Range("A1","A1").Value2.ToString());
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void …
Run Code Online (Sandbox Code Playgroud) 假设我有一个LINQ查询,必须使用查询语法:
foreach (var productId in (from batchOrder in batchOrders
let outputFileName = GetUniqueFileName(batchOrder)
let ssisResult = SendToSsis(productId, outputFileName)
where ssisResult == 0))
{
// Does something here
}
Run Code Online (Sandbox Code Playgroud)
而且,我需要引入一个新的操作调用,而又不会超出查询范围。如果我正在调用的方法返回一个布尔值,则可以使用let
关键字添加它:
foreach (var productId in (from batchOrder in batchOrders
let outputFileName = GetUniqueFileName(batchOrder)
let ssisResult = SendToSsis(productId, outputFileName)
// The next line is the new call
let trackingFiles = OutputTrackingFiles(batchOrder)
where ssisResult == 0))
{
// Does something here
}
Run Code Online (Sandbox Code Playgroud)
但是,如果该OutputTrackingFiles()
方法无效,该怎么办?如何在查询中包含该调用,而无需进行修改?
C#WebMethod是否可以接受与其客户端发送的不同的参数名称?
例如,给定客户端发送此消息:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetStatus xmlns="http://example.com/">
<Arg1>5</Arg1>
<Arg2>3</Arg2>
</GetStatus>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
是否可以重写现有的WebMethod以适应不同的参数名称?像这样的东西?
[WebMethod]
public string GetStatus(
[MessageParameter(Name = "Arg1")] string orderId,
[MessageParameter(Name = "Arg2")] string typeId)
Run Code Online (Sandbox Code Playgroud) 下面的代码显示睡眠(1)平均睡眠时间为2毫秒!
DateTime dt = DateTime.Now;
int i = 0;
long max = -1;
while (true)
{
Stopwatch st=new Stopwatch();
st.Restart();
System.Threading.Thread.Sleep(1);
long el = st.ElapsedMilliseconds;
max = Math.Max(el, max);
i++;
double time = DateTime.Now.Subtract(dt).TotalMilliseconds;
if (time >= 1000)
{
Console.WriteLine("Time =" + time);
Console.WriteLine("i =" + i);
Console.WriteLine("max ="+max);
System.Threading.Thread.Sleep(200);
i = 0;
dt = DateTime.Now;
max = -1;
}
}
Run Code Online (Sandbox Code Playgroud)
典型输出:
Time =1000.1553
i =495
max =5
Run Code Online (Sandbox Code Playgroud)
有些人可以解释一下原因吗?我该如何解决这个问题?!