I have a bot that plays a flash game automatically. I have loaded the flash object through an extended WebView a friend coded for me and I use native imports to send click messages to the handle. Everything works good for about 30 minutes. After that the bot, GUI and whole mechanism starts getting slower and slower, lagging more and more, eventually ending up clicking totally different coordinates. I suspect there's a memory leak or performance issue in my source code. How can I find that out or fix it?
Related
I have developed an application with 2 AxShockwaveFlash and textBlock.In AxShockwaveFlash there is 2 different flash files with their own animation and in the bottom of the form a textblock scroll some text(Ticker).While loading of flash my ticker get stuck and when the flash has some transition then also my ticker get stuck.
I am not getting any clue why my application responds slow while playing or transitioning a flash file.How can I track exactly the problem is?
The simple answer to : Why AxShockwaveFlash take so much memory or process while transitions? is simply because that Someone out there doesn't know how to code a transition without killing the CPU.
To be fair your question didnt give enough helpful info (which led to the rambling answer below). Many people will call something "a Flash animation" when that something is anything from simple text fading in/out.. to a full blown 3D engine game demo to.. some intensive realtime video pixel effects. Just happens to be done in Flash so it's a Flash animation, right?.
A) If you can improve the C# code... Look into improving your WPF/Textblock code
Because if your Textblock is getting slowed down by the additional loading of some multimedia elements (photo, sound, Flash etc) then you simply have to improve that Textblock code.
Is this slow WPF TextBlock performance expected?
http://social.msdn.microsoft.com/Forums/vstudio/en-US/378a1945-8f72-4641-a0b8-e8ba5a31eced/is-the-wpf-textbox-really-that-slow?forum=wpf
http://www.codeguru.com/csharp/.net/net_wpf/article.php/c18025/10-Ways-to-Improve-the-Performance-of-Your-WPF-Application.htm
B) If you can improve the AS3 code... Look for any CPU intense pixel activity. Use bitmapData.lock and .unlock if the transitions code uses bitmapData.
If the Flash is externally created by someone else then perhaps there is some ineffecient coding? Check CPU usage by loading just the SWF's (no Textblock). Also consider the nature of your Flash animations for example I've never known SWF's of advert banners & pop-up ads to NOT add CPU usage. I dont know what those people do with their "simple" adverts. Essentially if someone else made it, find an alternative. Else if you have the source code, improve upon the transitions function first amongst others.
This is a common problem with Windows. Over the years, it's something that I've noticed and it's really aggrevating me to the point where I just don't want to make apps anymore. So I've decided to try and fix it within my own apps.
When I minimize an app (for example, Visual Studio, Windows Explorer, Internet Explorer, Chrome, or any other app ever made) and leave it there for a while, there is a huge delay (of anywhere between 3 to 20 seconds) between the time I click the icon in the taskbar until the time it has reached WindowState.Normal again.
Why is this? Why doesn't Windows suspend processes when they are minimized on the Desktop? And how can I solve this problem within my own apps?
I have thought about using a Timer. Start the timer when I minimize my app, let it run for a while and say, after about 10-15 minutes of it being minimized, if it hasn't been restored yet, start releasing some resources in the hopes of freeing up some memory - which I assume would make the response time quicker so that it doesn't feel like I'm waiting in the ER when I try to un-minimize my app. But I am not sure if a Timer is the right way to deal with this problem, and I'm not even sure if this is the right solution. All I know is that I'm getting sick of this and I need to do something.
Has anybody dealt with this before? Are there any articles out there or is there MSDN documentation that addresses things like this?
How can I better manage resources in my apps so that they don't become so slow when inactive for a little while?
This problem is common to any app. Not just mine.
Edit: I'm not sure what to do. I always make good use of using() whenever something implements IDisposable, and I just don't know how else I can try and free up some resources or speed up the response times.
The symptomes you describe seem to indicate that your machine lacks physical memory. When you minimize an application and activate another, the minimized application has many of its memory pages swapped out to disk. When you activate back the application, pages belonging to other applications are swapped out to disk and the perviously swapped out pages belonging to the application you just activated are swapped into physical memory, taking a long time due to the relatively slowness of the hard drive. Solution: Add more RAM, it's relatively cheap. If your O.S. is 32 bit, you can go up to 4GB. If your O.S. is 64 bit, whatever your motherboard supports is the limit.
I have a software installed on my system which basically peeks my activity during working hours. It send a report saying how much time i was away from my system etc.
Since i m .net c# developer hence trying to break this system through my programming skills.
I have basically written up a windows form application which opens up an notepad for me and start typing some random characters into it. simultaneously it also performs some random clicks and moves the mouse cursor to give a feel that some one is on system and working even when i am not :)
I also use "SetThreadExecutionState" Pinvoke calls to keep system awake.I have also observed the User idle time and last interactivity time through "GetLastInputInfo" PInvoke system call while my mouse/keyboard are in automation process and it is also fine.
But this is not working for me. It works perfectly till 5 mins and then somehow it detects that user is not present on system.
any suggestions for the same.
Get a decompiler, crack-open the spying application and see how it is working inside. Only knowing the internal workings, you can create a "workable" any-spying program. But I would not bother with emulation of the activity, but rather spoof the way it reports to the server.
However, depending on where you live, it might be illegal to do these things and I would not recommend cheating your employer. And if spying gets on your nerves I'd also suggest to brush up your CV and start searching for a new job.
I am a C# developer working on conversions to Mono Android. These conversions work perfectly, except for when the phone times out or blacks out and the user touches the screen again.... The game is lost.
What is the simplest way of dealing with this? I have heard it referred to as the life cycle, and found many brief descriptions of this cycle without explanations of how to implement it with real examples, and especially, how to implement it with XNA conversions.
My first solution would be to have a 'Pause' method in the XNA game, and run that method for the 'onPause' of the Android. However there may be simpler ways of dealing with this, as I have heard there are simple Mono Android settings to pick that will deal with time outs and phone calls automatically.
What I ask is.. How do I make my XnA conversion continue to run through a phone call, screen timeouts, etc?
Might I ask if you are using MonoGame or simply the AndroidGameView that comes with Mono for Android?
If you are using AndroidGameView, I suggest you follow the convention of reloading the textures manually in OnLoad() as per the textured cube sample.
When using MonoGame, if you load textures via ContentManager.Load<Texture2D>(), reloading is handled for you. Textures loaded using Texture2D.FromStream must be manually reloaded in the GraphicsDevice.DeviceReset event.
As Andrew Russell pointed out, ExEn has the advantage that it doesn't need to reload the textures on every resume. However, it is still necessary (or good practice at least) to support reloading graphics resources on Android. On many devices your game will not be able to gracefully recover from switching away and back without it. ExEn currently has no support for reloading textures.
Xamarin are currently working on fixing a bug in AndroidGameView that will allow it to correctly resume where the device supports it. Once released, this should flow through to MonoGame.
Aside from reloading textures and other graphics resources, handling of the life cycle should be fairly trivial. MonoGame has not yet implemented the complete Windows Phone life cycle (ie the tombstone and rehydrate), but in my experience, it's not necessary. You can use the Game.Activated and Game.Deactivated events for things like showing the pause screen when resuming in-game.
I've written a WPF application (in Visual C# 2010 Express) that has 2 windows. The 1st has a various buttons, the other displays video using the MediaElement control. When a button is pressed, a video associated with it is played or stopped if it's already playing.
On my development machine (Windows 7, good graphics card, lots of memory etc), this runs fine. The only problem I've encountered is that when attached to the debugger it is very unstable but when run normally these issues go away.
Unfortunately when run on a much less powerful XP machine the videos run at 1-2fps. This is despite the fact that the videos run fine in Windows Media Player.
There seem to quite a lot of reports of poor performance for the MediaElement control (not to mention inconsistencies in what it can play) so I decided to look at some alternatives.
I tried a free library call WPF MediaKit (http://wpfmediakit.codeplex.com) that I thought might have some effect, however while I've got it to work on an XP machine, it resolutely refuses to display videos on my development machine despite using exactly the same code. I'm still hoping I can this to work but I'm not confident it will help given it's still using the MediaElement control behind the scenes.
I then tried using wmp.dll COM control (Windows forms rather than WPF) and even with the simplest app (new Windows Form project, WMP control added to form, and 1 line of code to set the URL on load) I get odd behaviour. With the debugger attached, it works across multiple monitors, but sometimes when it starts playing, it just repeatedly stutters over the 1st few frames and the only way to break it out of this seems to be to move it to the other monitor. If I'm not using the debugger, I don't seem to get the stutter issue but the video is only displayed on the main monitor, as soon as I move the window to the secondary monitor, it goes black.
So my question is has anyone experienced anything like the above and/or have a decent solution to it? It would be especially nice to find something that works consistently with and without the debugger attached!
Have you tried this library?
http://directshownet.sourceforge.net/about.html
There's also this .NET interface to VideoLAN media player, but that introduces a dependency to VLC:
http://wiki.videolan.org/.Net_Interface_to_VLC
WPF MediaKit does not use MediaElement behind the scenes, but instead uses the D3DImage interop class to provide high performance video to WPF.
WPF in XP has always been a hit-or-miss in terms of performance. You might want to take a look at the rendering tier to ensure WPF is fully hardware accelerating. Also make sure you have the newest video drivers available and that the GPU is capable.
-Jer