Click here to Skip to main content
12,954,601 members (54,508 online)
Rate this:
Please Sign up or sign in to vote.
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?
Posted 7-Jan-13 1:15am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

abdallah 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
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...
XNA "at least in graphics". And what, you think Windows is not in graphics? :-)
abdallah 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
Windows allows "to use memory", otherwise nothing would work... :-)
I tried to answer, in more detail. Please see my Solution 3.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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(...))[^].

abdallah 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
Don't be afraid of bothering, just ask a question; sometimes, you would need to ask a question separately.
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?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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[^].


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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100