Problems with multi threading and timers

Hi, i have an app which sends data to a LED display device. I have created a thread which will call a sub which will continuously loop and send data to the LED display device. But i realised that now besides continously looping checking for differences in data and send it to LED display, i also need to send data to the LED display every 1 or 2 min regardless there are differences in data or not.

So the situation now is........i have a thread that check for differences a send data when required and i think i will create another thread which will start a timer and sends data to the device every 1 or 2 min. But what if at the same time...both threads try to send data through the comm port...will there be any implications? Are there better ways to do this? thanks
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes there will be error, if the comm port is opened by a process and another process tries to open the same port. You can use flag variables to check if the port is free and if it is free, send data, if not wait until the flag is reset and then send.

  If I want to do the same program, I will develop a simple class which will automatically send data to the comm port every 1 or 2 minutes. The class will also have a public procedure to force send data, if the data is changed. that is it. you can use your own logic inside.

You can use Monitor class to ensure that two threads don't execute some code at the same time. If both threads belong to the same class instance, this can work by the following way:

' thread 1
' send data

' thread 2
' send data

Enter/Exit parameter must be some instance, the same in both cases.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I think 1 thread should be enough.. but let it fall through your wait state when changes detected or timeout....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.