我想执行命令行工具来处理数据.它不需要阻止.我希望它是低优先级.所以我写了下面的内容
Process app = new Process();
app.StartInfo.FileName = @"bin\convert.exe";
app.StartInfo.Arguments = TheArgs;
app.PriorityClass = ProcessPriorityClass.BelowNormal;
app.Start();
Run Code Online (Sandbox Code Playgroud)
但是,我得到一条System.InvalidOperationException消息"没有进程与此对象关联." 为什么?如何以低优先级正确启动此应用程序?
没有这条线app.PriorityClass = ProcessPriorityClass.BelowNormal;,应用运行正常.
我正在尝试在我正在开发的应用程序中使用.NET Backgroundworker对象.
互联网上的所有资料都说这个对象在"背景"中运行,但我无法确认这个后台线程确实以"低优先级"模式运行.出现这个问题是因为在Windows中(我假设)后台任务可以在"正常"或"低于正常"或"低"优先级模式下运行.
在我的应用程序中,我尝试通过调用...在DoWork函数内设置优先级...
Thread.CurrentThread.Priority=ThreadPriority.Lowest
Run Code Online (Sandbox Code Playgroud)
...
但这似乎没有效果.后台工作者是否忽略此调用?
我想解释一下:
我的应用程序是一个互联网客户端,从一个房间收集有关温度,湿度等的实时数据,并使用上传到网页(不是网络服务)
system.net.webclient.UploadValuesAsync(...) 电话
我编写了应用程序,以便客户端GUI收集来自分庭的数据,给它们加上时间戳,然后将它们排队等待上传,就像这样
...
Synclock objlock
debug.print("Queueing reading...")
dataQ.Enque(reading)
End Synclock
...
Run Code Online (Sandbox Code Playgroud)
backgroundworker的Dowork函数出列然后上传,就像这样......
..............
Do
if dataQ.count() <> 0 then
Synclock objlock
reading = dataQ.DeQue()
End Synclock
Dim client As New System.Net.WebClient
...put the reading in NameValueCollection and upload to server page
req = new NameValueCollection
...
...
client.UploadValuesAsync(uri, "POST", req)
endif
thread.sleep(1) 'without this line the CPU usage goes upto 100% and seems to slow other tasks!
Loop …Run Code Online (Sandbox Code Playgroud)