Hello. I want to design the correct application architecture by following MVVM. I need to simulate a video camera. I have identified two main classes: Π’ΠΈΠ΄Π΅ΠΎΠΊΠ°ΠΌΠ΅Ρ€Π° and Π’Π΅Π»Π΅Π²ΠΈΠ·ΠΎΡ€ . the first one will record video, and the second will stream recorded videos.

Model

 class VideoCamera { public Video video {get; set;} public void Record(){...} //запись Π²ΠΈΠ΄Π΅ΠΎ } class TV { public Video video {get;set;} public void Play(){...} //ΠΏΡ€ΠΎΠΈΠ³Ρ€Ρ‹Π²Π°Π½ΠΈΠ΅ Π²ΠΈΠ΄Π΅ΠΎ } 

It is clear that the Record() method should run in the background stream, I want to use BackgroundWorker for this and transfer once every 1 second a portion of the recorded video to the TV class. But the Rerort () method in BW, as I understand it, does not stop the background thread, it does not wait for the event handler it generates to complete. That is, it turns out I need to transfer a copy of the Video from the ΠΊΠ°ΠΌΠ΅Ρ€Ρ‹ to tv .

How to design VM these classes to achieve these goals?

  • And what is the simulation? - Arheus
  • @Arheus, I want to know how to properly transfer data that is loaded from the background to the main stream, for example, once a second. - Gardes
  • Yes, there is nothing difficult there, and with MVVM it is not connected. It is easy to get from the stream - in the background thread the line: Dispatcher.Invoke (here is the method from the ui thread). You pass the object to the method and you no longer hold links to it (so as not to create a section crit). Dispatcher, respectively, on the flow of UI (it is possible and the other, but depends on the task). - Arheus
  • In fact, 1 second of video is not compressed - it can be a lot (by volume, say 24 frames per second, fullhd, this is 5-6 Mb x 24 = 120-140Mb). Too much for second-allocation-removal. I would either "frame it" compressed frame by frame or, if you just have an imitation, then the stream itself can be transferred from the camera to output. In general, specify the questions, because The task is very vague now. - Arheus

0