Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, Iam programing a GIF Animator and Icon editor and I have a problem with the speed of the program, I've read some articles that talk about XNA but all of them about gaming and games not about apps, and my application use Graphics a lot even in its shape (Custom shape but with all Aero effects like shadow and dock....), So my question : Do XNA will help me? if yes how and if no what I could use instead?

Maybe, but the application you are talking about does not need tremendous performance at all. If you have performance issues in developing of such application, it simply means you seriously screwed up something, most likely the design. From you question, we don't know what exactly.

If we point out a faster platform for you, it cannot help you. First of all, you won't deliver the functionality for the platform you are currently working at, but if you change the platform, how can I be sure that you won't screw up performance is the same or other way. No, it cannot really help, because the platform is certainly not your bottleneck. It's just your code.

One Russian proverb says: "For a good dancer, even the legs is a hassle". (There is a more vulgar variant of this proverb, mentioning some other important body parts :-).) This is a case here, nothing else.

You can detect some bottlenecks in your code using some code profiler:[^].

It won't help you to solve the problem, because most typically the problem is in design, but in this case you will know where the problem comes from. And maybe you even will be able to ask a more specific question; than we could possibly help you to solve the performance issue.

Share this answer
Boudi AlSayed 7-Jan-13 17:48pm    
Thanks, but I don't have any problem with the code and I have no bottlenecks or loops, the problem is when a timer starts and the user is drawing and Some graphics Animations is playing to show what the user doing and the image size is too large, some timers and animations will be too slow. I will try to use XNA because it will help at least in graphics
Sergey Alexandrovich Kryukov 7-Jan-13 18:21pm    
OK, did I tell you that the problem is in design? Timer could be a problem, of course. What kind of timers do you use? Which one of all 4 our so .NET timer types? For example, if it is System.Windows.Forms.Timer, consider it killed all your application; never use it. Use thread and cross-thread invocation.

Same thing about WPF; this is a very different approach, and, by the way, considerably better performance, because it is based on DirectX.

If you don't understand the problems well enough, moving to a different platform may not help you. You can create some similar plus some different problems. Got the hint?
If you provide more specific information, I might help you. I created a good amount of graphics and animation with .NET, it always worked for me...
Sergey Alexandrovich Kryukov 7-Jan-13 18:26pm    
XNA "at least in graphics". And what, you think Windows is not in graphics? :-)
Boudi AlSayed 7-Jan-13 19:27pm    
Yes I use System.Windows.Forms.Timer, but how to use thread and cross-thread invocation? and yes the timer is the problem when I start it the app become slow. Thanks dude :-), and I know that windows is in graphics but it doesn't allow to use memory like it does if we don't know how
Sergey Alexandrovich Kryukov 7-Jan-13 19:48pm    
Windows allows "to use memory", otherwise nothing would work... :-)
Abdallah Alsayed asked:
…but how to use thread and cross-thread invocation?
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in[^],
Control events not firing after enable disable + multithreading[^].

Basically, in your second, non-UI thread, you should work only with data representing graphics. The main, UI thread, should only render the same data. You need to synchronize this data between threads. To render data, override the method System.Windows.Control.OnPaint of some control. It can be a custom control. To fight flicker effectively, use double buffering (please see control's options). When the data is modified in the second thread (call it "scenario thread"), simply invoke some delegate which calls Control.Invalidate on the rendering control. It will push WM_PAINT Windows message, so your OnPaint handler will be called. With updated data. This way, your animation will be pushed onto the rendering system.

You can also call one of the Invalidate methods with parameters, to render just the part of the scene and improve performance on the parts of the scene where the data was not modified by the animation (you will need to specify a Rectangle or Region for update. If you sequentially quickly invalidate several times with different subsets of the scene points, the involved regions will be merged before they reach the rendering.

This all gives you pretty good performance.

But even better performance can be achieved with WPF, because it is based on fast DirectX.

Please also see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

Share this answer
Boudi AlSayed 7-Jan-13 20:48pm    
Thanks, I think I will switch to WPF, because I've tested it now, its really faster. I don't want to bother you anymore but is it possible to make my WPF app style like Office 2013 or Visual Studio 2012 (custom shape) with all windows effects(shadow, dock ...), because I've wasted a month for making it in Win Form App [and it works :)] I don't want to waste more time I just want to know if possible? thanks again
Sergey Alexandrovich Kryukov 7-Jan-13 21:24pm    
Don't be afraid of bothering, just ask a question; sometimes, you would need to ask a question separately.
Sergey Alexandrovich Kryukov 7-Jan-13 21:42pm    
I just answered in sufficient detail, see my Solution 4.
If you accepted this answer formally, I hope you will like Solution 4 even more.
But what do you think about Solution 2? Still not convinced that I was right about performance?
It isn't possible to answer this question as we know nothing about what your app does nor how to implemented things, nor exactly what you mean by "poor performance".

For an editor, I highly doubt that XNA/DirectX is going to give you any benefit at all. On the surface it sounds as though something just isn't implemented correctly and changing out the entire graphics library isn't going to fix that.
Share this answer
Abdallah Alsayed asked:
…is it possible to make my WPF app style like Office 2013 or Visual Studio 2012?
It's apparently possible: if Microsoft did it, you should be able to do it, too.

To tell you more, there is even a good open-source ready-to-use solution, if we can talk about Visual Studio application design. It's called Avalon dock:[^],
with detailed documentation and tutorials:[^].

This library closely reproduces the features and style of Visual Studio. It is used in alternative open-source IDE called SharpDevelop:[^],[^].

In principle, you can download the whole SharpDevelop and find all parts needed to build the IDE. There is also Avalon Edit, with syntax highlighting for any language, code outlining, and, again, everything the development of Studio-like IDE may need. Those are all independent components.

Besides, there are articles and tutorials on CodeProject:
AvalonDock [2.0] Tutorial Part 1 - Adding a Tool Window[^],
AvalonDock [2.0] Tutorial Part 2 - Adding a Start Page[^],
AvalonDock and MVVM[^].

Share this answer

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