Is there a way to start a background thread that continually performs screen grab and pushes the screen grab to a socket?
I am currently working in RhinoPython.
Following is a part of what I have:
import Rhino RhinoDocument = Rhino.RhinoDoc.ActiveDoc view = RhinoDocument.Views.Find("Perspective", False) width = 1080 height = 720 size = System.Drawing.Size(width,height)` def updateOneSecond(): frames = 75 # i am targeting 75 fps, on a gaming rig for i in range(frames): capture = view.CaptureToBitmap(size) # the save to file is just hold in function # I want to stream it without storing it file_name = "E:\\....\\cap" + str(cyc) + str(i) + ".bmp" capture.Save(file_name) print("Process complete")
This is a demo example, where I am writing the screen capture to a file. For my actual use, I plan to set up a continuous loop, which performs the screen grab and serves the bitmap as a server to a socket address and another application(an Oculus) will be listening to that address and collect the bitmap data.
It is important to hand the control back to the user for working normally with the file. So I figured the continuous loop should be ideally located on a parallel thread.
I came across the following parts which I believe may be a solution, but I have no clue what exactly they do and the documentation didn’t covered them in much detail.
# the ForEach method kept asking for a thread as the first argument # i am not sure how do I create a new thread and pass it to that method import System.Threading.Tasks as tasks tasks.Parallel.ForEach(<some thread name>, updateOneSecond())
# Thread has some methods under it, which sound relevant with method names like # 'Invoke', 'Start', 'IsBackground', but I don't know to use them. from System.Threading import Thread, ThreadStart, ParameterizedThreadStart
Also, I came across posts which documented that document methods can’t be accessed from parallel threads, but there seems to be an ugly hack for it.
It’s in C# I think, and I am having tough time figuring it out.
Ugly hacks will work for me for the time being.
Any help will be appreciated.