Home > Net >  Task to build a Queue is out of sleep. How to fill in a wait Queue and executing Task after return?
Task to build a Queue is out of sleep. How to fill in a wait Queue and executing Task after return?

Time:05-03

If I have a request very low delay of data to deal with, such as var r=MD5 (STR) the result of the need to use the fastest way to get the MD5,

In accordance with the method of low-level, I in the Task in the following ways to do this,

While (true)
{
if (! String. IsNullOrWhiteSpace (STR))
{
STRR=MD5 (STR)
STR=null;
}
Thread.sleep (1);
}
But first of all, this method is not very beautiful, and query, sleep on the system is the minimum accuracy of 15 ms, and the data returned is relatively trouble, or events, or something similar to read while waiting for,,

Want to use the Queue attempts to achieve similar functionality, and don't know whether the Queue is relatively beautiful, fast waiting for data to be filled, convenient and fast return after processing the data?
Or ask if there is any other more appropriate method?


CodePudding user response:

Why sleep? Since in the pursuit of high speed, that want to sleep to do?

CodePudding user response:

The sleep here is to wait for the STR variable changes, and STR variable has changed to do the next step,
Mean, a Task need has been executed, and then the other Task to calculate the md5 demand, make the Task to complete,

CodePudding user response:

You mean the Task in a loop waiting for external data change? This is obviously wrong

CodePudding user response:

I know this kind of practice is wrong, but I don't know what other ways to replace this way?
First task cannot little, the example looks can save the task, but the task cannot little, actually, this task is fast md5 results back to the caller,

CodePudding user response:

So I advise you to stop this nonsense,

Before and after a few posts are over 2 month, no sense,

The said we all say, only the last advised by the way, the window is not a single task system, he can only in the "ready" thread round the execution, this is you don't escape, if you don't admit it, have to make the so-called 0 waiting thread, doomed to a futile work

Don't want to so I think you can give up c #, you can use c + + and WDK do a driver, according to, because the kernel driver go, walk interrupt,
Drivers can do your so-called 0 for, and can be the external calculation
  •  Tags:  
  • C#
  • Related