Home > Net >  C # how to press any key out of the white circle? It doesn't work?
C # how to press any key out of the white circle? It doesn't work?

Time:09-24

While ()//read from the database user information
{

//read from the registry default browser executable file path
RegistryKey key=Registry. ClassesRoot. OpenSubKey (@ "HTTP/shell/open/command ");
System. Diagnostics. Process. The Start (" https://seo.comcuz.com/");
System. Threading. Thread. Sleep (10000);
SendKeys. Send (@ "% + ({F4})");
}

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
break;
}


}

CodePudding user response:

We'll need to rev a thread, to just go

CodePudding user response:



reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
need to rev a thread, to just go


How to write multithreaded need?

CodePudding user response:

You define a Boolean outside keyforbreak;
Private bool KeyforBreak;
While ()//read from the database user information
{
//your code
}

CodePudding user response:

Wasn't written
Private bool KeyforBreak=false;
While ()//read from the database user information
{
//your code
If (KeyforBreak)
{
KeyforBreak=false;
break;
}
}
If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
KeyforBreak=true;
}

CodePudding user response:

Don't mislead people, and thread no anything to do,

Console. Readkey method will block the current thread waiting for input, just enter the specified characters can exit the loop and you just write the judge at the edge of the cycle in vitro, so that it can never be performed here, should be like this:
While (true)
{
. .

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
break;
}
}

CodePudding user response:

reference 5 floor datafansbj reply:
don't mislead people, and the thread didn't anything to do,

Console. Readkey method will block the current thread waiting for input, just enter the specified characters can exit the loop and you just write the judge at the edge of the cycle in vitro, so that it can never be performed here, should be like this:
While (true)
{
. .

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
break;
}
}

This also not line, you perform to input do not input will not down here,

CodePudding user response:

Multi-threaded positive solution, a thread to handle the original logic, a thread to judge the keyboard input

CodePudding user response:

Feeling is the cancellation of the thread and suspended,

https://www.cnblogs.com/zhengzc/p/10724839.html

CodePudding user response:

 
using System.Threading;
Class Program
{
The static void Main (string [] args)
{
Thread Thread1=new Thread (new ThreadStart (A));
Thread1. Start ();

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
Thread1. Abort ();
}

}
Private static void (A)
{
While (1==1)//read from the database user information
{
//your code
Console. WriteLine (" the next \ r \ n ");
}
}
}

CodePudding user response:

reference 5 floor datafansbj reply:
don't mislead people, and the thread didn't anything to do,

Console. Readkey method will block the current thread waiting for input, just enter the specified characters can exit the loop and you just write the judge at the edge of the cycle in vitro, so that it can never be performed here, should be like this:
While (true)
{
. .

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
break;
}
}

Sure to add a thread, you can't get to receive input from the user,

CodePudding user response:

references 9 f qq_38833921 response:
 
using System.Threading;
Class Program
{
The static void Main (string [] args)
{
Thread Thread1=new Thread (new ThreadStart (A));
Thread1. Start ();

If (the Console. ReadKey (true). The Key==ConsoleKey. Enter)
{
Thread1. Abort ();
}

}
Private static void (A)
{
While (1==1)//read from the database user information
{
//your code
Console. WriteLine (" the next \ r \ n ");
}
}
}

I this version, self-test OK

CodePudding user response:

The landlord did not describe the problem clearly, is constantly taking data for processing, press the return key to suspend? Or take a, and then wait for the enter key to suspend?
If the former, then you need to use the thread processing, if the latter, so don't need a thread to handle,
  •  Tags:  
  • C#
  • Related