c# - Timer in foreach with ManualResetEvent -


when click button, cycle starts read database , send each row of query server. when response - cycle continues.

code implemented follows

private manualresetevent _mre = new manualresetevent(true); 

and

thread startupload = new thread(() => {    //read database     foreach (datarow dr in dt.rows)       {           //send request           _mre.waitone();       } });  startupload.start(); 

the problem when requests sent may not answer. in case normal. if not, answer comes, cycle stops. need inside loop timer, in case of stopping cycle due lack of response continue cycle in 30 seconds.

the timer have do

_mre.set(); 

important: you're setting manualresetevent initial state true, set false if you're willing stop current process , wait signal.

edit:

example

private manualresetevent _mre = new manualresetevent(false);  private void readthedatabase() {     thread startupload = new thread(() =>     {         // read data          foreach (datarow dr in dt.rows)         {             // send request             thread requestmethod = new thread(() =>             {                 // imitate process thread sleep                 thread.sleep(5000);                 _mre.set();             });              requestmethod.start();              _mre.waitone(30000, false);         }     });      startupload.start(); } 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -