WPF ImageProcessor slow first time use - c#

In my WPF application i need to make thumbs from photo the user add to the program. To do this i use the ImageProcessor package which works perfect for me.
Bu i have one small problem the first use in an application session always takes 5 a 10 seconds to complete every next thumb making in the same session only takes milliseconds.
It looks like the DLL is only loaded on first use.
Is there a way to make this faster?
I've tried replacing ImageProcessor with ImageResizer and also tried loading ImageProccesor on application startup both didn't work.

I talked to the owner.
It appear to be the plugin search routine which was checking all referenced assemblies. My project uses many DevExpress components which gives me a few dozen assemblies in the project folder.
The owner has made exceptions in the search routine.
Issue on GitHub

Related

WebView2: Multiple instances of same application need to launch the same browser control

Problem
I recently replaced a System.Windows.Forms.WebBrowser-based control with one that relies on Microsoft.Web.WebView2.WinForms.WebView2 instead. This has been working well, except that my users want to have 2 instances of their application running at once, with both instances occasionally having that WebView2 form open at the same time. When they try this, one of the two instances fails to load the WebView2 control until the other one is closed.
Learned / attempted so far:
I've found WebView2 to be extremely finicky, so I've looked into alternatives like CefSharp, but haven't wanted to dedicate time to implementing them until I know they can solve the problem. So far as I can tell, CefSharp and WebView2 do very similar things as far as launching a Chromium-based browser, rendering to a WinForms control.
This blog post (read: advertisement) for paid alternative DotNetBrowser indicates that
You can initialize and use several Chromium engines simultaneously with different configurations [in DotNetBrowser], which is not possible in CefSharp.
I'm wondering if this same limitation applies to WebView2, and is the cause of my users' inability to have 2 instances of that same form loaded at once.
Context
I'm supporting an ancient desktop CRM that's set to be retired in favor of a modern alternative, but in the mean time, the old standard needs to integrate with new processes we're bringing in. One of those new processes is a web page from an external service that our call center users enter data into, then expect the CRM to pull entered data out of the web page.
The part of their process I did not know about is the 2-instance bit from above: they're used to being able to copy-and-paste from one embedded browser window to the other.
#Poul Bak in the comment on the question had it right: providing settings that differ per-instance of the application fixed the problem.
The setting I changed per-instance was the path of the user data folder: I was able to pass different values for the userDataFolder argument of the CoreWebView2Environment.CreateAsync method, branching based on a variable that holds different values between the instances that my users are running.

Controlling a browser using C# for streaming media

I'm trying to control a browser using C#. The way that used to work was OLE/interop. This seems to be missing from modern browsers. All I need it to do is be able to navigate to a URL and then change the URL from time to time. The problem using Process.Start("http://example.com") is this usually spawns several children processes and I can't determine the exact process to kill later. Calling it several times simply creates new children. I tried using the WebBrowser and WebView controls. Yes, these give me the control I want, but the rendering engine is embedded in the application and is so old, no sites allow these controls to work anymore.
I found something called WebDriver. At first this seemed like a good solution, except it appears to be very dependent on the exact build of the browser and has dependencies on Selenium. It probably works great for automated testing, I'm not convinced it will work well for long term browser control if the browser updates itself.
Next comes CefSharp. I've used this in the past, but it also seems to have an embedded and outdated rendering engine and many sites complain it too is out of date. And even if CefSharp gets updated from time to time, I need to rebuild my application each time. The problem I see here is, the rendering engine is embedded into an assembly that gets distributed with my app. Yes, I've seen a huge list of other embedded solutions. Many of them haven't been updated in years.
Ideally, I could control a browser using something like WebDriver that worked on any browser version. I could launch an external browser like FireFox or Chrome. Do any browsers have an API? Here's exactly the pseudo code I'd like to implement using a modern browser:
ModernBrowser br = new ModernBrowser();
br.Navigate("about:blank"); // clear out last page
if(some_flag)
br.Navigate(Url); // navigate to new page.
If(done)
br.Close();
br = null;
That is all I need. Dead simple.
I'm trying to implement a media playback system. All the code works fine except where I need a modern browser to play back Pandora, Spotify or any other web based systems. They all require the latest browser versions or they simply don't work. Embedding a rendering engine in my application is a nightmare. Sure, I can get it to work today. I'm just not sure about tomorrow.
I decided to try CefSharp and it works. I realize I'll have to update this from time to time. I want to point out that if you decide to use CefSharp as an embedded browser, don't use NuGet on your live project. Create a throw-away project and install the CefSharp assemblies. As of the date of this entry, the Nuget install breaks your C# project and makes every assembly unusable. What I did was I created a throw-away project, added the CefSharp assemblies and then took the dependent binaries and put them in a new folder. I made my live project an X86 target and that works.

Spell check textbox in Win10 - Slow

I'm using the built in spell checker in WPF. It was working just fine until I had users start upgrading to windows 10... I think the issue is that it's being used for a lot of small text boxes. My application presents a grid (Telerik's TreeListView) with text boxes for one of the columns which i want spell checked. I need to be able to provide a custom dictionary to the spell checker; the only way I was able to do this was to subscribe to the textbox loaded event and add the paths in as follows:
TextBox tb = sender as TextBox;
tb.ContextMenu = ctx_Spell;
IList dcts = SpellCheck.GetCustomDictionaries(tb);
dictsList.Add(dcts);
if (KMApplication.Settings.UserDictionary != null)
{ dcts.Add(KMApplication.Settings.UserDictionary); }
foreach (Uri dct in KMApplication.Settings.RevitDictonaries)
{ dcts.Add(dct); }
Granted this calls the add for each and every text box which seems terribly wasteful, but it seemed to be working just fine with little noticeable lag and only on load up. However now on Windows 10 it seems to be a ridiculous lag. On my Windows 8.1 machine I load up a file with a few thousand rows and it appears in about 3 or 4 seconds; on my Windows 10 box, it appears in about 10-15 minutes. If I comment out the custom dictionaries portion of the above code it's back to about 3-4 seconds on either machine.
Does anyone know a better way to do this? Or if there is some way around it in Win10?
We have experienced a similar issue and saw improved performance by avoiding re-registering custom dictionaries on every TextBox control during load.
Unfortunately, we hit another issue with the way custom dictionaries are handled which can also result in very long loading times if you have even a small number of TextBox controls.
When a WPF application registers a custom dictionary in .NET 4.6.1 on Windows 8.1/10, a temporary dictionary file is created in %localappdata%\Temp and this is registered in the multistring value _GLOBAL_ in the registry key "Computer\HKEY_CURRENT_USER\Software\Microsoft\Spelling\Dictionaries".
If the _GLOBAL_ value ends up referencing a dictionary file which does not exist, the application starts to exhibit very slow loading whenever a control with spell check enabled is initialized.
This can happen by using the "Stop debugging" button in Visual Studio and then running the Disk Clean-up or CCleaner after enough time has passed for these to delete the temp dictionary files.
We managed to fix this by clearing the _GLOBAL_ value of any links to dictionary files which did not exist. The our application began to work as expected.
We raised the following connect bug:
https://connect.microsoft.com/VisualStudio/feedback/details/2153484
Starting .NET 4.6.1 (in Win8.1 & Win10), WPF uses ISpellChecker interface exposed by the OS to implement its SpellChecker, and the performance characteristics could be somewhat different indeed.
Notably, ISpellChecker's custom dictionary registrar acts globally - it no longer acts as a per-control registration. (See KB article link below). As a result, registering the same set of dictionaries over and over for each control is wasteful and can potentially degrade your performance. Besides, the OS will just start ignoring your dictionaries when it reaches an internal limit.
Just register the dictionaries once, or use the alternative registration mechanism outlined at http://blogs.msdn.com/b/wpf/archive/2015/10/29/wpf-in-net-4-6-1.aspx and place the files under %appdata%\microsoft\spelling\.
If you need to run the same application on Win7/Win8 as well as Win8.1/Win10, you may need to detect the OS and branch your dictionary registration strategy.
In general, typical uses of custom dictionaries should continue working as usual - with little difference between .NET 4.6.1 vs previous releases.
Also see https://support.microsoft.com/en-us/kb/3088234 for additional information.
Firstly, I want to mention that I know that the post is already a few years old but I think that my answer might help someone out there who has the same problem but where the presented solutions didn't work (like myself).
What fixed it for me was to add the following code to App.config:
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.DoNotAugmentWordBreakingUsingSpeller=true"/>
</runtime>
Alternatively you can also insert the following code after your InitializeComponent() call:
AppContext.SetSwitch(#"Switch.System.Windows.Controls.DoNotAugmentWordBreakingUsingSpeller", true);
Source 1 (XAML solution)
Source 2 (C# solution)

Slow Performance -- ASP .NET ASPNET_WP.EXE and CSC.EXE Running After Clicking Redirect Link

I click on a link from one page that does a redirect to another page (Response.Redirect(page.aspx)).
The browser churns for about 30 seconds and the page displays. I'm trying to track down why it takes so long to load the page.
The page hosts two other custom controls.
I have commented out the lines of code for each and both controls, and the page still takes about 30 seconds to load.
I've set breakpoints on the Page_Load event for each of the controls as well as page.aspx and it also takes about 30 seconds from clicking the link with the Response.Redirect to the first break point.
I loaded up task manager and clicked on the link. I notice aspnet_wp.exe and csc.exe run during this 30 second time frame.
I'm wondering if there are some sort of code-behind shinanigans going on while I'm waiting for the page to load.
This only occurs the first time I click on the link. Afterwards, it's not as slow.
I've googled but there's not a lot of useful information about this. Anyone have any ideas?
Thanks,
---Dan---
The very first time that the page is load, then the asp.net compile a lot of pages, almost every one found on the same dir, including modules, and dlls found on bin.
To speed up (your development) try use this option on web.config (only on your development computer).
<compilation batch="false" ... >
Using batch="false" asp.net compiles only one page, the one you are on it, so you get a big time the first time for the dlls, but after that, is a lot less if you have 200 pages, and you only change one, and you develop/debug only one.
Also if you can, try do not use App_Code directory, and place all your code inside a dll.
Look more about compilation options on web.config to make it even run faster, change for example the temporary directory to a faster different disk than the C:.
Second trick
I will like to say one more trick that I found here on stackoverflow.
<compilation optimizeCompilations="true">
You only need to have install an ms patch http://support.microsoft.com/kb/961884
I have test it and the results are very good.
.net 4 and Visual studio 2010
The same think stands, but you do not need to run the patch.
Web Farm
I have notice that on web farm the first time that application is run, if you have many work on global.asax on application start, then I recoment to use Mutex and let only one pool make the compile of the pages ! Or else there are possibilities for conflicts and huge delay to start the application - especial if you use mutex on other part of the program.
The fact that csc.exe is running and it only occurs when you first click the link would suggest there are a lot of elements in the aspx that need to be compiled prior to displaying the page. Look for stuff that exists in expression holes <%= %>. It could also be something in the controls themselves (particularly if they are ascx user controls and not server controls).
The reason it only happens the first time you click on the link is because after that the compiled page object is cached, so there is no need to re-compile until your app is restarted.

C# Making a Frontend to a Console Program?

I wrote a console program in c# that takes up to three files as input, and does some data calculations on them.
I'd like to make a simple frontend that allows the user to easily
import files - basically choose up to three files to be routed to the backend code
change settings - I have about 10 settings that I'm currently storing in an app.config file. maybe a simple settings box would be nice
see what's going on - the console program shows some status messages that might be useful to display on a GUI
I have practically no experience with windows forms or GUI design, so I really don't know where to begin. I compiled the backend stuff into a *.dll and am currently playing around in design mode of sharpdevelop...but i really have no idea how to get the two to work together.
any pointers would be greatly appreciated!
The usual pattern, in cases like these, is to make the main features of the application into a class library and call that from a wrapping executable, such as a console app, winforms app or webforms app (if possible). That way you can easily adapt the interface as needed and simply route input and output to and from the class library.
Edit: I realize this isn't a very indepth answer, but I hope it helps to get started at least, together with any other answer that may arrive.
If you want to get started with GUI design in .NET, I recommend you choose WPF (Windows Presentation Foundation). This is the latest technology released in the UI/graphics area by Microsoft and is where everything is heading now. (Windows Forms won't be obsolete for a long time, though it is surely but slowly becoming deprecated.) I noticed however that you are using SharpDevelop, which doesn't yet have real support for WPF (as far as I know), whereas it certainly does for WinForms. If there's any chance you can use Visual Studio, I recommend you begin by learning WPF. You have the advantage of not being confused by previous experience with the styles and methodologies of WinForms, so it would very much be the right way to go.
Whichever you wish to learn, the Getting Started page of WindowsClient.NET (the official MS site for both WinForms and WPF) would be a great resource. There's also a few MSDN articles on getting started with WPF.
Hope that helps.
Have you tried Visual Studio Express editions? They're free and come with a designer for either WinForms or WPF applications.
As a first pass you'll need 3 text areas for the filenames, with associated buttons to bring up the file open dialog (it doesn't actually open the file just returns the filename).
A label to display the status - updated from your worker code.
Then either the various radio buttons, check boxes etc for your configuration settings.
Oh and don't forget the "Start" button to set off your process.
If your process takes a while you ought to use a background worker thread. You can then implement a "Cancel" button to safely abort the process and tidy up if it goes wrong.
There will be optimisations and reorganisations that you can do once you've got it working.
Your question is quite indistinct. If you're asking about working with GUI, you should read some book on Windows Forms.
And if you're asking about how to put your dll in your new windows forms application, then you should just add a reference to it in winforms project's properties and then use classes from dll's namespace.

Categories