Problem
I have a constant stream of data. Each time a new packet arrives (100 ms interval), an event occurs in which I send the packet to the class for data processing and visualization. Unfortunately, it may happen that the package process is interrupted if a new package was sent before the current one was processed.
What i have now
Is the code that is used as a dll for another program. When I started coding dll, I was new to C #, so I did not want to do this too complicated. Everything works, but I came across some ugly frames (in my part of the visualization) if the processor is very busy.
I have several classes, and one of them handles all the packages. This class has about 50 attributes of 25 functions and 1000 lines of code. Only 6 functions are required for calculations. The rest sets the attributes correctly (if the user changes the settings).
What i need to change
So now I want to buffer all incoming data using List. The list must be processed by another thread. Therefore, it is very unlikely that writing data to the list takes more than 100 ms ^^ (2 arrays with approximately 40 elements that should be equal to nothing)
What I mean
Division of the mentioned class into 2 separate classes. One that handles packets, and one that handles settings. Therefore, I would separate the user and the input of the "program". Create a stream that uses the packet processing class to process buffered data.
What i don't know about
Since the settings class contains important attributes necessary for the processing class, I do not know how to do this best, because the processing class must also modify / fill the buffers in the settings class. But this will be caused by the main thread. Or is it better not to separate the setting and the processing class and leave it as it is? I am not very familiar with threads and read the first chapter of this free e-book Threading in C #
source share