Non obstructive wait, using WaitForSingleObject.....
darn clicked on wrong button question finished not posted
hi all,
i trying write c# app interface board have designed have used serialdatareceived event to pick data issue need way of using asynchronous read waitforsingleobject how can used in c# examples can find c++.
what trying write app interface board via usb serial
the issue using monitor can see data being sent , replies happening 2 crossing. complete string sent , wait for ok, > or period of time (.timeout) i think waitforsingleobject might need example.
public int waitfordata(int timeout) { // bool respond = false; //bool waitforprompt = false; stopwatch sw = stopwatch.startnew(); this.invoke(new methodinvoker(delegate() { replydata = rtbincoming.text; })); //if((replydata.contains(">")||(replydata.contains("ok")))) // respond = true; //else // respond = false; while (sw.elapsedmilliseconds < timeout && mycomport.bytestoread > 0)// && respond == false)// && rtbincoming.text.contains(">") || rtbincoming.text.contains("ok")) { lblwhere.text += "."; system.threading.thread.sleep(1); // sleep 1 millisecond } int elapsed = (int)sw.elapsedmilliseconds; sw.stop(); return elapsed; }
this routine called via value = waitfordata(10);
i hoping use value of elapsed value appears 0 time.
glenn
hi glenn,
i sorry mistakes , got startnew() new stopwatch().
yeap, stopwatch.startnew() same as:
stopwatch sw = new stopwatch();
sw.start();
but issue is, thread.sleep(1).
in default, stopwatch accurate to 1 milliseconds. so, 1 ignored. if tried thread.sleep(2) , print elapsedmilliseconds, shows 1. first milliseconds lost.
use frequency and ishighresolution fields determine precision , resolution of stopwatch timing implementation:
frequency: gets frequency of timer number of ticks per second.this field read-only.
ishighresolution: indicates whether timer based on high-resolution performance counter.this field read-only.
best regards
neddy ren[msft]
msdn community support | feedback us
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment