![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
|
I am trying to make a program the will monitor if the certain variable changes.
lets say if the default value is 0, the program will just listen, but when the value changes to 1. something will happen. here is what i have thought Code:
Do Until Exit_button is clicked If val != 0 Then Execute Statement End if Loop |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 43
OS: Windows Vista x64
|
Re: Monitoring a Variable
The reason it does this is because the application is divided into threads, you are executing an endless loop on the form thread, which causes it to lock up. What you need to do is create a sub thread (multi-threading) for the application. Take a look at this, maybe it will help:
http://www.dreamincode.net/code/snippet875.htm Alternatively, you could use a Timer and set the interval to 1 sec and in the timer tick's code you can handle what happens if it changes. Side note, why not just use an on click method for the button instead of waiting for the button to be clicked by using loops? |
|
|
|
|
|
#3 (permalink) |
|
Registered User
|
Re: Monitoring a Variable
since i am monitoring a parallel port. when the value on that status port changes. it should run a event and send a signal to the motors drivers. the trigger is a laser and a photo sensor when the laser light is blocked a change in the status port will happen. since we don't know when will that happen it should be monitored.
|
|
|
|
|
|
#4 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 43
OS: Windows Vista x64
|
Re: Monitoring a Variable
Ah, i just kinda glanced at the code, yeah try running the loop in another thread with the background worker and see if that helps you any. The timer is probably easier to implement but is kind of a work around and may cause problems later on.
Last edited by daniel142005; 12-30-2008 at 01:49 PM. |
|
|
|
|
|
#5 (permalink) |
|
Registered User
|
Re: Monitoring a Variable
i try running the background worker component, and now i need to periodically to produce a report. like a text box text that says "Monitoring" every lets say 1 sec. since BGW uses a different thread i can't just change the values of the texbox, and the RunComplete event of the BGW will only happen when i cancel or finish the task, how can it be overcome?
|
|
|
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 43
OS: Windows Vista x64
|
Re: Monitoring a Variable
Your going to need to use delegates and invokes to communicate between threads. Check here: http://addressof.com/blog/archive/2005/02/10/1287.aspx it has some tutorials on Threading in VB .NET.
|
|
|
|
![]() |
| Thread Tools | |
|
|