通过交叉线程设置 3 个不同标签的多个值 c# winforms
Setting multiple values of 3 different labels via cross threading c# winforms
所以我得到了一些在 USB 连接事件上运行的代码。如果检测到 android 设备,它会运行一些与 build prop 相关的代码。然而......它只设法 return android 版本,没有别的。代码如下。
private void Main_Shown(object sender, EventArgs e)
{
var watcher = new ManagementEventWatcher();
var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Query = query;
watcher.Start();
}
private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = process.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = process.StandardOutput.ReadToEnd()));
这应该是 returning 3 个值并将它们放入相应的标签中。但是只有一个是 returned。有什么办法可以改进代码来做到这一点?
shell getprop ro.*
在较早的版本中工作并且没有被更改...
原来我是个傻逼。
我为所有内容设置了相同的流程,但它引发了错误。真的是菜鸟错误。我太沉迷于自己的炒作了……
新代码
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = p.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = pr.StandardOutput.ReadToEnd()));
所以我得到了一些在 USB 连接事件上运行的代码。如果检测到 android 设备,它会运行一些与 build prop 相关的代码。然而......它只设法 return android 版本,没有别的。代码如下。
private void Main_Shown(object sender, EventArgs e)
{
var watcher = new ManagementEventWatcher();
var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Query = query;
watcher.Start();
}
private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = process.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = process.StandardOutput.ReadToEnd()));
这应该是 returning 3 个值并将它们放入相应的标签中。但是只有一个是 returned。有什么办法可以改进代码来做到这一点?
shell getprop ro.*
在较早的版本中工作并且没有被更改...
原来我是个傻逼。 我为所有内容设置了相同的流程,但它引发了错误。真的是菜鸟错误。我太沉迷于自己的炒作了…… 新代码
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "shell getprop ro.build.version.release";
process = Process.Start(startInfo);
device.Invoke((MethodInvoker)(() => device.Text = process.StandardOutput.ReadToEnd()));
Process p = new System.Diagnostics.Process();
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.RedirectStandardInput = false;
si.CreateNoWindow = true;
si.RedirectStandardOutput = true;
si.RedirectStandardError = false;
si.UseShellExecute = false;
si.FileName = "adb.exe";
si.Arguments = "shell getprop ro.product.model";
p = Process.Start(si);
AV.Invoke((MethodInvoker)(() => AV.Text = p.StandardOutput.ReadToEnd()));
Process pr = new System.Diagnostics.Process();
ProcessStartInfo siy = new System.Diagnostics.ProcessStartInfo();
siy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
siy.RedirectStandardInput = false;
siy.CreateNoWindow = true;
siy.RedirectStandardOutput = true;
siy.RedirectStandardError = false;
siy.UseShellExecute = false;
siy.FileName = "adb.exe";
siy.Arguments = "shell getprop ro.product.name";
pr = Process.Start(siy);
name.Invoke((MethodInvoker)(() => name.Text = pr.StandardOutput.ReadToEnd()));