I have a c# ui that makes calls to a C dll. The UI opens a workspace, and I’d like the DLL to load a large file in the background while the user is doing other work in the workspace. Right now, the UI communicates with the DLL with the help of pinvoke. (The loadFile is one of the C dll functions.)
At some point the user will do something in the workspace that requires that the file be fully loaded, so there would be a need to somehow query the DLL whether it has finished loading the file. I have the source for the c# and C code, so I could change things on either side.
Being new to c#, and never more than an amateur C coder, can I achieve what I want using a c# backgroundWorker?
Or using some form of threading?
Or will the C dll just block everything until it is done loading?
You can invoke the C function from background worker component. Further you need to make sure that completion event of background worker is fired. This can be set using properties of background worker.
This way, when the background worker finishes its job, it will notify the user interface that the work is done and the user interface can appropriately treat the image.
Here, you have to make sure that your C code is Blocking, i.e. NOT multithreaded to ensure that the background worker event is fired only after the function has done its work.