Richtextbox for = i 多功能 [英] richtextbox for = i multiple function
问题描述
我正在寻找我的问题的答案,在这里我向您清楚地说明情况.
I am looking for the answer to my question, here I clearly explain the situation to you.
我有一个富文本框,其中包含 10 行.
I have a richtextbox, and 10 lines included.
第 1 行线2线34号线5号线..第10行
line1 line2 line3 line4 line5 .. line10
我正在这样做;
For i = 0 to richtextbox.Lines.Count = - 1
Button1_Click;
Dim getlist as Process = Process.Start("cmd", "commands" + richtextbox.Lines(i))
getlist.WaitForExit()
Next
我试过了,但没用;
Dim getlist as Process = Process.Start("cmd", "commands" + richtextbox.Lines(i))
Dim getlist2 as Process = Process.Start("cmd", "commands" + richtextbox.Lines(i + 1))
当我这样做时,它就像;
when I do this, it gets like;
第一:richtextbox 第 0 行和第 1 行
first: richtextbox line 0 and line 1
getlist 从 line1 开始,getlist2 从 line2 开始
and getlist starts line1 and getlist2 starts line2
我希望它像;
获取列表:line0getlist2: line1
谁先完成,函数开始换行;
and who finishes earlier, the function starts to get new line;
例如:
获取列表:line0-line2-line3-line5getlist2:line1-line4-line6
我怎么能这样做?非常感谢所有答案!
how could I do this? thanks a lot for all answers!
推荐答案
为了做到这一点,您需要使用某种基于线程的解决方案来并行执行.其中最直接的方法可能是使用基于 Task
的异步方法.
In order to do this, you'll need to use some sort of threading-based solution to execute in parallel. Probably the most straightforward of these is to use Task
-based asynchronous methods.
最终看起来像这样:
Dim T1 = Task.Run(Sub()
Dim getlist as Process = Process.Start("cmd", "commands" & richtextbox.Lines(1))
getlist.WaitForExit()
End Sub)
Dim T2 = Task.Run(Sub()
Dim getlist as Process = Process.Start("cmd", "commands" & richtextbox.Lines(2))
getlist.WaitForExit()
End Sub)
然后,您将能够使用各种方法来等待一项或两项任务完成.如果您将包含例程标记为 Async
,您可以Await
T1
或 T2
.您也可以 Await Task.WhenAny
在任一任务完成后立即继续.
Then, you would be able to use various approaches to wait for one or both tasks to finish. If you mark the containing routine as Async
you could Await
either T1
or T2
. You can also Await Task.WhenAny
to continue as soon as either one finishes.
我强烈建议阅读有关基于任务的异步的 MSDN 文档.特别是,您应该阅读实现基于任务的异步模式",因为有关交错和节流的部分可能适用于您想要做的事情.不幸的是,我的在线帮助副本中的示例都是 C# 格式的,但这些材料应该可以直接转换为 VB.
I would strongly recommend reading the MSDN documentation on Task-based asynchrony. In particular, you should read "Implementing the Task-based Asynchronous Pattern", as the sections on Interleaving and Throttling are likely to be applicable to what you want to do. Unfortunately, the examples are all in C# in my copy of the online help, but the material should be straightforward to translate to VB.
这篇关于Richtextbox for = i 多功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!