G
Guest
Hi.
I have 3 questions. For the short version: skip to the end of the post
For those of you who has some time over: Here comes the long version of the questions, with some background.
I’ve done a program that sends a small message on the comport and then receives a large chunk of data. When I’ve received my data I want to let the user start fiddling with it. But at the same time I’d like to start a little code running in the background. This new code should send 4 small messages/second on the comport and receive a value each time, which I’d like to display to the user while he’s fiddling with the other data. This seems to me like a task for multiple threads, right? (Haven’t used ‘em before…)
Since I need other tasks to run at the same time, I guess I can’t just use a timer. I had an idea of having a thread running a separate class with the background program. The thread could run the code and then sleep for 250 ms. Does that seem like the right way to go about? Although that wouldn’t make the 250 ms interval very accurate, since it would depend on the execution time of the code. How would I get the code to start running with exact interval?
Another problem I have is that I need to call procedures in other classes. As far as I can understand this demands that the called sub is public and shared, but then I get problems since that sub often refers to instance members of that class (such as controls) and even properties of other instanced classes. I could perhaps try to make everything shared, but that doesn’t seem like a good way to solve things. Or is it the only way?
This also applies to my “background codeâ€, since I’d like it to call a procedure in another class (the code handling communication with the comport). But can one do that with a separate thread? Do I need to rewrite that code inside the thread?
In short:
1. How to run code at exact intervals (using threads)?
2. Is it possible to somehow use instanced members when calling a sub in another class?
3. Can a thread call procedures outside of its class?
I’d be very thankful for some help on any of my questions.
/D
I have 3 questions. For the short version: skip to the end of the post
For those of you who has some time over: Here comes the long version of the questions, with some background.
I’ve done a program that sends a small message on the comport and then receives a large chunk of data. When I’ve received my data I want to let the user start fiddling with it. But at the same time I’d like to start a little code running in the background. This new code should send 4 small messages/second on the comport and receive a value each time, which I’d like to display to the user while he’s fiddling with the other data. This seems to me like a task for multiple threads, right? (Haven’t used ‘em before…)
Since I need other tasks to run at the same time, I guess I can’t just use a timer. I had an idea of having a thread running a separate class with the background program. The thread could run the code and then sleep for 250 ms. Does that seem like the right way to go about? Although that wouldn’t make the 250 ms interval very accurate, since it would depend on the execution time of the code. How would I get the code to start running with exact interval?
Another problem I have is that I need to call procedures in other classes. As far as I can understand this demands that the called sub is public and shared, but then I get problems since that sub often refers to instance members of that class (such as controls) and even properties of other instanced classes. I could perhaps try to make everything shared, but that doesn’t seem like a good way to solve things. Or is it the only way?
This also applies to my “background codeâ€, since I’d like it to call a procedure in another class (the code handling communication with the comport). But can one do that with a separate thread? Do I need to rewrite that code inside the thread?
In short:
1. How to run code at exact intervals (using threads)?
2. Is it possible to somehow use instanced members when calling a sub in another class?
3. Can a thread call procedures outside of its class?
I’d be very thankful for some help on any of my questions.
/D