Hello

I'm relatively new to Microsoft Visual Studio. Now, the project that I am working consists of a GUI class and two separate classes (lets call them A and B). I am working on the GUI and one of the other classes (A). Basically, these classes interact woth some hardware (A is used for communication, B for Data Acquisition, the details are not relevant)in real-time meaning that we use timers (1ms to 25ms for class A, 1s upto 30 s for B). Now, my friend is working on the class B. In the end, we would need to integrate the codes since I will be providing the GUI. Also, some of the variables of my class A may need to be accesed by class B.

In a similar project done by one of my other friends, they encountered a problem while working with timers. Specifically, they would notice that for e.g the communications timers wont work if the code for the acquisition took more time than the min. timer interrupt for the communication code. They suggest using threads.

So my question is, how would I do this for the classes GUI, A and B as described?

Thanks!

http://www.albahari.com/threading/

This was the best resource I found when starting to work with threads. If I understand your problem correctly, you either want to Sleep each thread to wait for the other to do its work, or possible create a resource lock until your data acquisition thread completes its work, and then the communication thread will gain access to the resource and, well, presumably it will communicate with something.

Anyways, hope this helps.
/H

commented: :) excellent link +14

hey thanks for the link...i'll look into it.... the problem that we are trying to work asround is the following specifically:

1) lets say there is a timer that interrupts every 1ms for the Communication class....the code that is executed takes less than 1 ms each time that timer is called so there should be no problems
2) there is a second timer that is called every 30 s for acquisition....the code it runs takes more than 1 ms i.e. it won't be able to run correctly before the 1 ms timer interrupts....
By using threads, we hope to avoid this mainly.... I hope that makes the problems statement clear

Specifically, they would notice that for e.g the communications timers wont work if the code for the acquisition took more time than the min. timer interrupt for the communication code. They suggest using threads.

Can you please provide more detailed issue description?
Its hard to tell you a solition on this poor explanation.
note: threading is mainly used if you work with data that are time consuming (read: more seconds, and more). So I doubt using threading will salve your problem.
As said, if you will provide us more info, we will be able to see what is actually going on, and what to do to salve it.

OK i guess that I am not making much sense so I will try to explain in another way, differently. I currently have 3 classes:

1) a main GUI form class
2) a data processing (non form class)
3) a dialog form class

all of these are defined in their own separte classes.

now, the data processing class is declared in the main GUI class. also, some variables of the main GUI class are passed into the data processing class and vice versa
for e.g. a function in the data processing class may look like this

public void UpdateFile(GIU gui)
.
.
.
.

similarly, on the press of a button in the GUI, a dialog box may appear use the dialog form class.

What i want is to have a main file that declares the main GUI as thread and the data processing class as a thread without changing the interlinks between them much.

Thanks!

ok asking around a bit I understand that you cant call classes in threads rather functions are called...so I will try to explain my problem in another way (please ignore the above post)

private void timer1_Tick(object sender, EventArgs e)   //called every 1 ms
{
    //some code that takes less than 1 ms to execute

}

private void timer2_Tick(object sender, EventArgs e)  //called every 30s
{
    //some code that takes 2-5 seconds to execute
}

Now the question is that will timer1 cause the code execution of timer 2 to be interrupted before it is completed? If so, is there any method (using threads or some other way) to avoid this i.e. let the code of timer2 run in parallel with timer 1.... Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.