Reputation: 9013
I have an WPF application, which has the following code:
public static BitmapSource ToBitmapSource()
{
using (var screenBmp = new Bitmap(Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth),
Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenHeight),
System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (var bmpGraphics = Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen(0, 0, 0,
0, screenBmp.Size);
return Imaging.CreateBitmapSourceFromHBitmap(screenBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
}
}
and some code below. Its code executes when user selects the feature in app. Problem is this code executes long time, but only when app starts first time on this PC. If user deinstall and install again this app - it works quickly. Questions:
- How to "rollback" a system to check this problem again and again (don't want to reinstall Windows for one start)
- The best way to debug (place, which really do program slowly)
- How to fix it :)
Thanks
Upvotes: 1
Views: 103
Reputation: 91
First of all, use a profiler (SlimTune, for example) to find out the boutleneck.
Upvotes: 0
Reputation: 1111
i dont work in wpf, but try doing the time consuming work in a separate thread, that might solve your problem.
Upvotes: 0
Reputation: 2357
Upvotes: 1