I read this on code project.... "Not long time ago, I was programming an application for Windows that every certain time had to execute a task; in the development of the project everything went with normality but arrived the day to prove the program in the definitive machines where it had to remain working, and we observed that once in a while timers stopped working. We did thousand verifications always reaching the same result, sometimes, timers provided by the Framework don't tick, no events fired. It was then when we began to look for a solution to replace these timers and the solution that seemed better to me was the one to replace them by timers of the API of Windows. We looked on the Internet in case somebody had had the same idea that I had, without success, and therefore put hands to the work." the address for this article is http://www.codeproject.com/csharp/FTwin32Timers.asp?target=timers Does anyone have any comments? In my application i really cannot afford for a timer not to fire. maria
maria_p
Posts
-
timer -
MSComm serial port control HELP!!!HELP please someone I'm using MSComm with C#.....at the moment I'm communicating via a null modem connection between 2 PCs. At the moment I'm just sending out some bytes from one PC to another PC... Got the communication to work... all is well. The problem; I only expect something to be sent from one PC to other when I press a button on the sending PC which then uses the command object.Output= new byte [] {a number}; to send a byte to the other computer.... the recieving computer in turn recieves this and displays it via the ONComm event handler. The ONComm event on the recieving PC is raised when a byte arrives at the recieving PC serial port on pressing a button on the sending PC.... HOWEVER the ONComm Event is also raised (on the recieving PC)when I start up and exit the sending application. I just can't understand this! This could obviously be a really big problem... Can someone explain or have a solution to this? I would be grateful... I just can't seem to stop this event from raising when the sending application starts up or shuts down... This could be reallly disasterous if the sending PC sends something on start up (ie without me even having instructed the sending application to output a signal by pressing a button) when connected to a PICmicrocontroller which shouldn't recieve that signal.... Here is how i set up the 2 PCs; com.CommPort = 1; if (com.PortOpen) com.PortOpen = false; com.RThreshold = 1; com.Settings = "9600,n,8,1"; //com.DTREnable = true; com.Handshaking = MSCommLib.HandshakeConstants.comNone; com.InputMode = MSCommLib.InputModeConstants.comInputModeBinary; com.InputLen = 0; com.NullDiscard = false; com.OnComm += new System.EventHandler(this.OnComm); com.PortOpen = true; Here is the ONComm event handler on the recieving PC which is connected with a null modem cable; // MSCommLib OnComm Event Handler private void OnComm(object sender, EventArgs e) { //Message box 1 MessageBox.Show("recieved something 1"); switch (com.CommEvent) { case (short)MSCommLib.OnCommConstants.comEvReceive: //Message box 2 MessageBox.Show("recieved something 2"); byte[] x = (byte[]) com.Input; foreach (byte byt in x) { strrecvd += (char) byt; //Message box 3 MessageBox.Show(strrecvd);........................ The only Message box that should show on the recieving PC is 3 and that only when I press a button to send a byte on the sending PC... However on the inclusion of message boxes 1 and 2 I noticed that when I started up or shut down the sending applic
-
Help with MSComm serial port communicationsHELP please someone I'm using MSComm with C#.....at the moment I'm communicating via a null modem connection between 2 PCs. At the moment I'm just sending out some bytes from one PC to another PC... Got the communication to work... all is well. The problem; I only expect something to be sent from one PC to other when I press a button on the sending PC which then uses the command object.Output= new byte [] {a number}; to send a byte to the other computer.... the recieving computer in turn recieves this and displays it via the ONComm event handler. The ONComm event on the recieving PC is raised when a byte arrives at the recieving PC serial port on pressing a button on the sending PC.... HOWEVER the ONComm Event is also raised (on the recieving PC)when I start up and exit the sending application. I just can't understand this! This could obviously be a really big problem... Can someone explain or have a solution to this? I would be grateful... I just can't seem to stop this event from raising when the sending application starts up or shuts down... This could be reallly disasterous if the sending PC sends something on start up (ie without me even having instructed the sending application to output a signal by pressing a button) when connected to a PICmicrocontroller which shouldn't recieve that signal.... Here is how i set up the 2 PCs; com.CommPort = 1; if (com.PortOpen) com.PortOpen = false; com.RThreshold = 1; com.Settings = "9600,n,8,1"; //com.DTREnable = true; com.Handshaking = MSCommLib.HandshakeConstants.comNone; com.InputMode = MSCommLib.InputModeConstants.comInputModeBinary; com.InputLen = 0; com.NullDiscard = false; com.OnComm += new System.EventHandler(this.OnComm); com.PortOpen = true; Here is the ONComm event handler on the recieving PC which is connected with a null modem cable; // MSCommLib OnComm Event Handler private void OnComm(object sender, EventArgs e) { //Message box 1 MessageBox.Show("recieved something 1"); switch (com.CommEvent) { case (short)MSCommLib.OnCommConstants.comEvReceive: //Message box 2 MessageBox.Show("recieved something 2"); byte[] x = (byte[]) com.Input; foreach (byte byt in x) { strrecvd += (char) byt; //Message box 3 MessageBox.Show(strrecvd);........................ The only Message box that should show on the recieving PC is 3 and that only when I press a button to send a byte on the sending PC... However on the inclusion of message boxes 1 and 2 I noticed that when I started up or shut down the sending applic
-
Multithreading issueYes thank you Sir, what you have said and the way you put it has given me a totally different way of looking at the issue (Excellent analogy!)... still a little confused about one issue though.... regarding the event at the serial port.... If various threads are executing in the application will the system get a chance to acknowledge the/an event (which I am expecting at some point) that may take place due to something arriving at the serial port? Or when one thread looses control another thread will immediately take control and due to this the possible event will be missed or seriously delayed? Is there a way around this or am I just missing the point about something? If you could also explain this I'd be most grateful. maria
-
timerDear Heath Stewart, :) Thank you ... your reply has given me alot to go on! Thanks Maria
-
Multithreading issueHi Folks, I wonder if somebody can either point me in the right direction or explain a certain concept to me... i just can't figure it out (i've browssed through MSDN)...If in an application I have several threads running and while these threads are running something arrives on the serial port of the computer...Using a control I can raise an event to signal this "BUT" will the application be aware that this event has taken place? Or how can I make sure that the application is aware that something has been recieved at the serial port while other threads are running?.... Please can someone help... A secondary issue also related ... say again multiple threads are running in an application, in one thread I implement a lock on a certain portion of code (so this must complete execution before any other thread can resume control)... if a timer raises an event (or is due to raise an event) while another thread is executing a portion of locked code... will this timer event be lost by the time the locked code in the other thread completes??? can anyone help!!! I'm desperate... can't find this information anywhere... Maria (phillips_maria@hotmail.com)
-
timerFirstly I thank you for your reply (i have never used a message board before). Secondly to bug you some more... I don't know if i was told the wrong thing but i was told that for automation purposes using operating system timers wasn't a good idea... do u have any thoughts on this? When i say automation... my application will control a couple of robots.... If say I were to use the timers that you have mentioned above ... is there a way of finding out the resolution of their Ticks? also which of the above timers should i use? And you say that this is as accurate as i'm going to get?
-
timerHello everyone, really struggling here......Can someone clear up a few issues for an inexperienced C# student...I need to implement a precise timer (ie not the ones supplied invisual studio.net)I need the timer component to act 1) like the .Net timers available ie. i set a time say 2 seconds and when this time has a elapsed an event is raised? 2) the elapsed time that raises an event may be less than 1 second that is something like miliseconds. 3)i implement several of these timers in one single application (perhaps using threads)? Basically I am communicating serially with another computer (was quite difficult using C# until I discovered somewhere that you can use the MSCOMM control)... and I need to set up several timeouts. For instance I send several messages to the other computer and for each message I expect a reply in a certain amount of time. So I send a message and then I want to start a timer... when a certain amount of time elapses say 500 milliseconds then i want an event to be raised as a visual studio timer would do..... If anybody has any comments advice snippets of code with a little explanation or even other sources of help .... i would be truly grateful! Maria (phillips_maria@hotmail.com)