Which approach better: Process.Start or call DLL directly?
In our team we've faced with the choice: we need to call external third party code and process its output from our C# code.
The third party code available in two forms: set of dll
s and single exe
file (which is probably calling these dll
s on its own). And possible approaches could be: use Process.Start
statement to run executable and catch its output. And another one is to call dll
directly.
I'm trying to understand which approach should we use.
On one hand calling executable is simple, but on the other — it does not feel robust.
On one hand calling dll
looks more right way to do the job, but on the other — it might be really complex task to provide C#
binding for all functions we have in native C
code.
But I need more substantial analysis on this topic to make a final decision. Does anybody faced with the same question before, maybe you could share your finding.
It would be very useful!
EDIT : I'm talking about video conversion in this particular case. I need to get video stream from user and convert it into one video format for all. It is possible to call ffmpeg
to do the job, and everything is OK until something goes wrong and I need either restart encoding or take any action. I could not estimate how long it will take and if I will need to convert several videos in parallel ffmpeg
will not be that flexible, as I plan it to be...
At least as I see it now. Maybe more issues will come up as I dig in.
There are several considerations:
Depending of the answers.
Create bindings if:
Use executables:
I'd say this would depend on how much granularity would your code expect in terms of api support from the library.
If executable encapsulates the workflows well enough for you, you could benefit from simplicity of invoking the executable.
Also, since you mention this is native C code, adding DLL reference would mean having to deal with unmanaged code, which I'd personally not go for unless there is no option for me.
如果dll编写得很好,并且没有内存泄漏,那么最好使用dll,因为它不需要新的进程创建开销。
链接地址: http://www.djcxy.com/p/68912.html