Vb.net net多进程
这是我的场景,我有两个sendkeys应用程序(使用计时器),我将其重写为一个,但我有一个问题,例如,如果我启用计时器1,它将发送大量的“q”,直到我停止它,然后如果我启用计时器2,它将发送“1”,然后是“2”,然后是“3”。该过程的输出是Vb.net net多进程,vb.net,sendkeys,Vb.net,Sendkeys,这是我的场景,我有两个sendkeys应用程序(使用计时器),我将其重写为一个,但我有一个问题,例如,如果我启用计时器1,它将发送大量的“q”,直到我停止它,然后如果我启用计时器2,它将发送“1”,然后是“2”,然后是“3”。该过程的输出是 qqqqq123q123q123q123q123q123q123q123q123q123q123 这不是我想要的,在我合并两个sendkeys之前,输出会给我类似的东西 qqqq1qqq2qq3qqqqqq1q2q3qqqq1 两个计时器的间隔相同。当我将
qqqqq123q123q123q123q123q123q123q123q123q123q123
这不是我想要的,在我合并两个sendkeys之前,输出会给我类似的东西
qqqq1qqq2qq3qqqqqq1q2q3qqqq1
两个计时器的间隔相同。当我将这两个计时器合并到一个运行的应用程序中时,会发生类似于timer1、timer2、timer1的情况,它们喜欢交替处理,而不是同时处理。希望有人能帮助我。thx看看这个参考: 它说: 此Windows计时器专为单线程环境设计,其中 UI线程用于执行处理 这是单线程的,因为计时器的间隔是相同的。它们将按顺序处理。您应该改用System.Threading.Thread。 请参见下面的示例。您可以创建一个参数化线程对象,该对象将字符串参数作为sendkeys应该在该线程上发送的内容。并启动两个或更多线程
using System;
using System.Threading;
// Simple threading scenario: Start a static method running
// on a second thread.
public class ThreadExample {
// The ThreadProc method is called when the thread starts.
// It loops ten times, writing to the console and yielding
// the rest of its time slice each time, and then ends.
public static void ThreadProc() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("ThreadProc: {0}", i);
// Yield the rest of the time slice.
Thread.Sleep(0);
}
}
public static void Main() {
Console.WriteLine("Main thread: Start a second thread.");
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread. C# simplifies the creation of this delegate.
Thread t = new Thread(new ThreadStart(ThreadProc));
// Start ThreadProc. Note that on a uniprocessor, the new
// thread does not get any processor time until the main thread
// is preempted or yields. Uncomment the Thread.Sleep that
// follows t.Start() to see the difference.
t.Start();
//Thread.Sleep(0);
for (int i = 0; i < 4; i++) {
Console.WriteLine("Main thread: Do some work.");
Thread.Sleep(0);
}
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.");
t.Join();
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.");
Console.ReadLine();
}
}
使用系统;
使用系统线程;
//简单线程场景:启动一个静态方法运行
//在第二个线程上。
公共类线程示例{
//线程启动时调用ThreadProc方法。
//它循环了十次,向控制台写入命令并让步
//其余的时间每次切片,然后结束。
公共静态void ThreadProc(){
对于(int i=0;i<10;i++){
WriteLine(“ThreadProc:{0}”,i);
//产生剩余的时间片段。
睡眠(0);
}
}
公共静态void Main(){
WriteLine(“主线程:启动第二个线程”);
//Thread类的构造函数需要ThreadStart
//委托,表示要在上执行的方法
//C#简化了此委托的创建。
线程t=新线程(新线程开始(线程进程));
//启动ThreadProc。请注意,在单处理器上,新的
//在主线程运行之前,线程不会获得任何处理器时间
//被抢占或放弃。取消对线程的注释。休眠该线程
//跟随t.Start()查看差异。
t、 Start();
//睡眠(0);
对于(int i=0;i<4;i++){
WriteLine(“主线程:做一些工作”);
睡眠(0);
}
WriteLine(“主线程:调用Join(),等待ThreadProc结束。”);
t、 Join();
WriteLine(“主线程:ThreadProc.Join已返回。按Enter键结束程序”);
Console.ReadLine();
}
}
这个例子来自:你的问题不清楚:
他们喜欢交替过程,而不是同时进行。
如何同时发送模拟键盘输入?这不是量子计算机;)正如我所说,你的申请将按顺序处理它们。我的问题是,当我没有在一个应用程序中合并代码时,我如何才能使输出像这样,我通常在两个应用程序上这样做,它工作正常,试着同时按字母a和字母s,就像那样,它不会尽快给你输出。它会给你一些类似于Assasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasas。