Simulate Cold Boot? - c#

I'm debugging a problem to do with our custom splash screen and am wondering how I can simulate the longer loading time of a C# application on a cold boot.
I don't mean by adding a sleep events when the application loads up. I mean somehow adding a delay in the load up of .net or maybe creating a dll to reference that somehow I can hack to take far longer to load.
I appreciate this is an odd request, but is there anything I can do?

Related

My C# application is in a loop, how can i find the position in the code?

I have written a rather large application running in the background, doing dome stuff and processing some data.
Now the problem is, for some time the application runs fine. But when I check a day later for example the Backgroundworker of my application seems to loop or stuck. There is no error message and the UI of the application is still running fine. It just stops processing data.
Specifically for this case I added a simple website for myself where the Backgroundworker reports the current DateTime. So when the DateTime on the website is somewhat current I know it is running fine. But when it's in the past I know my application is stuck.
The issue comes after a undefined time. It can be 10 minutes or 90 Hours.
Now for debugging: Is there a way in Visual Studio that I can see where the application currently is? That would make debugging a whole lot easier. Otherwhise I would have to set breakpoints on trial-and-error base...
Best regards,
Julian
you have two options:
1.- attach the debugger as it is suggested already and check the code, but if the application runs fine for a long time, it is not the best idea.
2.- log files. Create log files to track your application.
What I would do: I would combine both options. Add log files to check results and when the application reached certain points (to decide by you) and then, once I know more or less where the problem is, use the debugger.
Good luck
Edit:
I fully concur with this answer but would add that you may benefit from making the background worker pass key position information back to the UI as it enters and leaves particular sections so that you can simply interrogate this when you attach. Since the problem can take several hours to manifest itself you could end up with a lot of log file to wade through unless you use a rolling log with limited entries, continuously setting a telltale would at least allow you to know approximately where to put the breakpoint at that moment.

Performance issue when launching WPF application

I have a complex WPF application that is using a lot of resources from the shared Resource Dictionary.
The first Window initialized takes 8 seconds to initialize. The performance issue is less on SSD disk drives but still it requires 2 seconds.
I tried to use the Visual Studio Profiler and it shows big expense of time on InitializeComponent();
of the windows that needs to be displayed.
I believe it is related to the Resource dictionary used but I can't replace it because I really need it and because all windows and WPF elements are using the StaticResource references.
I tried to optimize the launch as much as it is possible.
I created many background threads but this didn't helped too much. Whenever a window needs to be displayed it must be attached on UI thread under the same Dispatcher. This makes a big performance issue and all UI and any Progress bar left on the screen is blocked.
So to summarize. From the point when the ShowDialog is called until the window is displayed it
takes 8 seconds. This is visible only on the first window. Any other window opened after that is displayed quickly.
Now I am asking firstly what happens in the background and why this delay is so big and second what can be done to increase the startup speed.
I didn't mentioned but there are no Exceptions or DataErrors present during the launch so it is
not related to Exceptions.
I believe it is something with the initialization of Buttons and other components because almost all of them have the ControlTemplate restyled.
Lots of assemblies need to be loaded and lots of code must be JIT compiled before your first window can be shown. One useful technique to reduce startup time is to structure your code in such a way that types are not loaded before they are needed. It may be preferable to get a blank window up on screen with a wait indicator before delving into code outside of the core WPF assemblies. Optimize for that scenario.
Avoid loading images/media and other resources too early if you are trying to get something up on the screen as soon as possible.
Avoid loading any data synchronously, and do as little in your view and view model constructors as possible. Defer the loading of data until your view has been shown (throw up a wait indicator if necessary).
If you think your Xaml resources are a problem, split them up, and have each view pull in only the resources it needs. Don't merge them into App.xaml. You might also look into how to share the resources more efficiently across multiple views.
Throwing up a splash screen can improve the perceived startup time. Getting anything up on the screen to let the user know your app is actually doing something goes a long way.
Lastly, don't fret too much; poor startup time is the hallmark of WPF applications, and in the end, there's only so much you can do.
You can also use the ProfileOptimization class to improve startup time over subsequent sessions of the program. May not help you, the developer, but may have an impact on your users for the better.

WPF application stops interacting on screen rotate

We have a WPF app which runs fine, but a user reported that it locks up when the screen is rotated. (Tablets will do that!)
The app actually renders fully after the rotate but stops responding to the mouse/keyboard. It doesn't show as 'non-responding' in a Windows sense.
We can simulate the "lock up" here, but debugging this is odd:
Lock up does not occur while in VS debugger
If you try and attach to the locked up process, VS says the process was built without debug information
Before the lockup VS can attach/deattach to the same EXE process
We have put trace outputs in global unhandled exceptions but nothing is fired.
I can only think of one next step to debug which is start to hack out chunks of code and find the breaking area.
Anyone seen this before or got any suggestions?
Thanks!
The issue was with an update library we were using called Sparkle.
It was creating a hidden WinForms form in it's constructor. There must be some kind of WPF/WinForms interop bug during screen rotations. Removing that form or removing the library fixed the issue.

Does playing a Program from VS2005 cause a program to work any different than the .exe file?

There is a program where I work that works fine when running the .exe file but works differently from expected when opened in VS2005 and played from there. I am therefore asking on here if anyone knows of anything that would work in the .exe file but not the debug from VS? I am not able to post the code for the buttons I'm talking about but I'll try to explain the best I can.
There is a receiver hooked up to the computer. When the button is pressed on the program, it shows a message and waits for a signal to be received. After the signal is heard the first message box is supposed to close and another is supposed to open. When using the .exe file this happens just fine. However when playing from the program from VS2005 (the same one from which the .exe was made) the second message doesn't come up when it is supposed to and when I can make it come up, the first box doesn't close. There is also a timer involved if that helps.
Also, is there a fundamental difference between how the two operate when executing the program?
If I need to make anything more clear or give more details please let me know.
Running a program under the supervision of a debugger can change the timing of events compared to running the program standalone. The debugger slows things down. Normally, this doesn't make any difference to the operation of the program, but if you have code that is dependent on the "coincidental" rapid timing of some activity, that happy coincidence may be broken when things slow down under debugger control.
The debugger can also cause changes in focus and activation depending on where you set your breakpoints - generally not a good idea to set a breakpoint in focus change or activation events because stopping at the breakpoint will change focus to the debugger, away from your app. But these are interaction issues. Just running your program under the debugger with no breakpoints shouldn't affect focus or activation in your app.
Review your code carefully. Consider what could happen to your program flow if you inserted delays between every source code statement. If that could lead to problems, you have a design bug that needs to be fixed. Reliance on coincidental timings will lead to bug reports and support calls, particularly if your customers have slower hardware than your development machine.
When you run under the debugger, or even in the VS testing host, there are some subtle differences. This shouldn't effect your program under normal circumstances, however, since most of the differences are similar to running (the debug version) of your application on a slower system.
Given your descriptions, I suspect that your problem is actually due to calling to the UI from a different thread than the control was constructed with. Make sure to always marshal any calls to the UI using Control.Invoke or Control.BeginInvoke.
It may be an issue with the Host Process, disabling it is a painless click and just as easy to re-enable. It may be worth giving a try.
Disable Host Process
I know this can effect Direct X and other API but I've never had exactly the situation you are in so I make no promise.

How can I speed up the opening of a WPF window in a VS add-in?

I have a Visual Studio add-in which opens a modal WPF window.
My problem is that the first time round, it takes 4 seconds for the window to appear which is a clear disservice to the client. So I'm wondering if there is a way to optimize this away?
Is there some kind of nifty code to preload the PresentationFramework (or whatever is slowing the thing down) when the add-in starts, rather than when it is actually used?
You may want to check your output window in VS to see if the pause is actually from loading DLL's that it didn't have already loaded. If that's the case, then you can try this:
When the application starts, load a blank hidden WPF window and close it.
This should "pre-load" the presentation framework (if that's actually the problem - its sometimes hard to tell with these cases.), so that when you call the needed window its ready to open.
Not the best solution, but users can usually wait 4 seconds in the first place.

Categories

Resources