通过交叉线程c#winforms设置3个不同标签的多个值
所以我得到了一些运行在USB连接事件上的代码。如果检测到android设备,它将运行一些与构建道具相关的代码。然而。。。它只返回android版本,其他什么都不返回。代码如下通过交叉线程c#winforms设置3个不同标签的多个值,c#,multithreading,winforms,label,settext,C#,Multithreading,Winforms,Label,Settext,所以我得到了一些运行在USB连接事件上的代码。如果检测到android设备,它将运行一些与构建道具相关的代码。然而。。。它只返回android版本,其他什么都不返回。代码如下 private void Main_Shown(object sender, EventArgs e) { var watcher = new ManagementEventWatcher(); var query = new WqlEventQuery("SELEC
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()));
这应该是返回3个值并将它们放入相应的标签中。然而,只返回了一个。有什么方法可以改进代码来实现这一点吗?
而
shell getprop ro.*
在早期版本中工作,并且没有被更改…结果证明我是一个derp。
我为每件事都设置了相同的流程,但它会抛出错误。菜鸟的错误真的很严重。我太沉迷于自己的宣传了。。。
新代码
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()));