Why windows forms application is different under C++ and C#

Hello, everyone

I'm new to this forum, after gaining lots of knowledge from it.

Now I try to build a GUI for trading platform. I use visual C++, but the program doesn't run as I thought. I searched online, and changed my code in C#. Both code are almost the same. But the C# version can run smoothly.

To define "run smoothly", I mean, when I click start button in both programs, they all start to show random numbers; but C# program can move the window when it's running and click stop button to stop it. While on the meantime, the C++ version doesn't allow user to move window or click Stop button. It looks like the thread occupies all resources. I want my program can be maximized or minimized when processing.

If anyone who is interested in my program, I can send him/her. I can't paste them here.

Thanks for any help.


C++ Does not nativley support multi-threading so yes what ever operation you give it will "peg" the process while it is running. It also doesn't really support parallel processing which would be what you need to put the thread on hold while you are moving the window. These are both things you have to write in yourself. C# on the other hand has a large framework to pull alot of these default operations from so that you don't have to write them yourself.

Did you change the default case in your windows call back function? Or redefine the conditions and leave them blank? Because it usually includes things like redrawing the window when it moves, minimizing, maximizing etc.
Last edited on
I would have to see your C# code to be sure, but it sounds to me that you are either pumping messages inside the random number generator loop, or you created a worker thread to generate those, while in your C++ code you don't do either.

Basically, the process of moving the window or re-sizing or mini/maximizing is handled by the window procedure. The window procedure is called whenever the message pump retrieves a message for the window. The processing takes place in the thread that created the window, and from your explanation, I suppose your C++ code doesn't explicitly create any threads, so this means that your thread cannot do the message pumping while it is generating random numbers.
Thank you guys both. I think I'd better read through this site:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
again to gain more knowledge about the so called BackgroundWorker class.
Thank you!
Topic archived. No new replies allowed.