Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a multi-threaded windows desktop application that runs on a standard PC motherboard. It collects images from cameras , displays them onto the UI, performs image processing on these pictures, also displays the results onto the UI and sends information via the Serial port to the PLC to control an external component. It’s a time critical system that repeats this sequence of steps every ~ 50ms. At times, there is a fair amount of user interaction while all of the computations are going on. In summary, standard operation involves app running with the images being collected , analyzed, results being displayed on the GUI and communicating with the PLC.

The legacy code is 100% MFC 6.0.

The main goal is to upgrade the GUI – without sacrificing the current speed.

1.What are some recommendations on rebuilding/upgrading this application?
2.Would a WPF front end / C# back end work, and be as fast as legacy?
3.Would a Windows Form front end / C# back end work, and be as fast as legacy?
4.Would a Windows Form front end / C++ back end work, and be as fast as legacy?
5.How would the 1st 3 options compare to simply upgrading the app to MFC 11
6.How will moving to a managed framework affect speed and repeatability?

Any thoughts would be greatly appreciated!

If this app were not time critical, I would go to C#. I’m concerned that by upgrading the GUI and by moving to managed code, I’m sacrificing speed. It’d be great to be able to ascertain the risk before making this decision.
Posted

Assuming 'code reusing' is not a requirement (otherwise you probably would have already followed the MFC 11 migration path), I would do some tests toward the fully managed path (that is all C#) with option 4 (that is C# GUI, C++ for time critical components) as plan B.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Jan-15 13:41pm    
Make sense, 5e. Please see my answer.
—SA
I rather agree with Solution 2. My answers:

1. Quick Questions & Answer might be not the most suitable place for such a wide problem, but main idea could be: don't assume you migrate; you create the system from scratch, because the technologies are very different. Consider it as a benefit: you can build new system properly, not replicating old mistakes.

2-3. It depends on how good or bad old application was. Other answers give you some ideas.

4. I would not draw the boundary between C++ and .NET between front and back end. In general case, it won't give you any benefits. Rather, you can try to leave C++ pieces which are certainly well written, in particular, with very good efficiency. Say, if you created very fast C++ image processing, your can use it while showing the result of processing in .NET UI. For interoperability, you can use P/Invoke, but it would be much better to use C++/CLI, which is a standardize language (under ECMA 372; please see the links below). You can utilize the possibility of creation of mixed-mode (managed+unmanaged) C++/CLI project with really smooth boundary between managed and unmanaged. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://www.gotw.ca/publications/C++CLIRationale.pdf[^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[^].

5. No way. Please see above.

6. What repeatability? It everything is written correctly, without race conditions, only timing can be non-repeatable, not logic. Timing depends on many factors; so it's impossible to give one short answer. Again, you can fill bottlenecks with faster C++ code, but it all depends on how it's all engineered; many managed to create much slower code with C++… Don't forget that, in particular, you can also go away for .NET JIT delays by using NGEN. Please see:
http://en.wikipedia.org/wiki/Just-in-time_compilation[^],
http://msdn.microsoft.com/en-us/magazine/cc163610.aspx[^].

—SA
 
Share this answer
 
v2
Comments
CPallini 15-Jan-15 13:53pm    
5. Very good. C++/CLI is indeed a not already suggested, good idea.
Sergey Alexandrovich Kryukov 15-Jan-15 14:23pm    
Thank you, Carlo.
—SA
Vitaliy Kunin 15-Jan-15 15:37pm    
I do mean repeatability in terms of timing.

Thanks to all who answered.
Sergey Alexandrovich Kryukov 15-Jan-15 15:59pm    
With non-realtime systems, you never ever has repeatability in terms of timing. With, say, Ethernet, you also don't have repeatability in terms of timing, due to its design. It does not mean if this is managed or unmanaged code. It's really important not to have race conditions though, which could be explained and the incorrect dependency of order or execution upon timing.

You are welcome. Good luck, call again.

—SA

It's depends on how much your core implementation is coupled with your UI. For instance, if you use a window handle to the window that the graphic should be paint on, in your core code (not a recommended pattern but, I already saw an implementation like this), creating UI with a new platform can require changes in the core implementation too. In addition to that, while the underlying model of rendering the Windows Form is same as MFC in that issue (depends on windows handles), in WPF it's completely different (depends on DirectX). So, in that case, WPF may be removed from the options list.


But, if your UI is completely decoupled form your core, you can keep your core implemented with C++ and, write a WPF UI for it. For more details about wrapping C++ implementation to be used with C# code, you can read my CP article about: Exposing native to managed - C++/CLI vs. P/Invoke.

 
Share this answer
 
It is not so much the CPU load that I would fear in a managed environment, but the unknown interference of the garbage collector.

Splitting the app into a managed front end and a C++ non-managed backend gives you nice options for the UI (Windows Forms), but you are introducing some complexity by creating a mixed debugging environment. For that reason, I would stick with a pure C++ application. That decision could be debated, however.

Whether to use MFC11 or creating your own, more modern UI environment is up to you. I would go for the latter.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Jan-15 13:40pm    
The complication you mentioned is not that bad if C++/CLI is used. Why so many forget this powerful possibility? Please see my answer. It's good that you mentioned that your suggested decision could be debated. I would rather say, it more depends on OP's project goals and resources/asserts they have. (I up-voted the answer with 4.)
—SA
CPallini 15-Jan-15 13:53pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900