I'm creating a C#.Net application which I want to be able to compile for "All CPUs". I also want to include a specific ActiveX control in the UI of this app, but the ActiveX control I'm trying to use does not support 32 bit. Is there some trick or work around I can use to use get this control to work?
What about embedding the ActiveX control in a Web-browser control? Would this even work?
You have to run the ActiveX control in a separate 32-bit process. That's going to be difficult, it would have its own window that isn't going to be part of the UI of your 64-bit process. Although it is expressly forbidden by the SDK docs, you can try to take advantage of the Windows 3 appcompat built into the SetParent() API function. It might work.
You'll have lots of additional trouble, communicating between processes is tricky enough (you'll need Remoting or WCF), the hard part is dealing with exceptions. One process bombing with the other one surviving and never noticing that something is wrong is not going to be pretty.
Perhaps the Platform Target option starts sounding attractive?
You can't load 32 bit components in a 64 bit application, but you can wrap the component in its own process and use IPC to leverage the features of the component. Of course this may not be feasible depending on the actual component.
Related
We have a very complex software primarily written using .NET WinForms in C#. Many people have contributed to it. One such contribution was the addition of a Windows Presentation Foundation (WPF) control hosted in Win Forms. The said control is considered a common control and used in many places in the application.
Everything was working fine till a few days ago when we started seeing inordinate delay in launching the application. The application used to launch in less than 5 minutes, but now takes 20 minutes to launch.
We have been analyzing the situation but have found it very hard to pin down the real issue. We have seen that our misbehaving common control that is used at multiple places, eventually calls the following framework functions:
The time taken by the system functions to perform their duties is shown in the picture above. The system functions take around 1.5 minutes each time the common control is initialized. We use the common control at least 8 times in our application. So, a total of 12 minutes.
Has anyone else seen such issues with WPF controls hosted on WinForms?
Any help would be appreciated.
EDIT:
There is an issue with C# Dictionary we use. Getting rid of it by using a List<> solves the delay issue. Microsoft has reproduced the issue at their end. They are working on it.
Maybe, our application took C# Dictionary to the edge ;)
Thank you all for providing your inputs.
This is likely to be the Initialization of the WPF control rather than something to do with the ElementHost or the fact that it's hosted within WinForms.
Without seeing the code for the WPF UserControl its hard to tell you what that might be but I would say that the interop of WPF / WinForms is certainly a red herring.
You can try using the Ngen:
The Native Image Generator (Ngen.exe)is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly.
If the assemblies of project will be compiled with help of Ngen, there is no need to run every time JIT-compiler before starting application and loading metadata of using assemblies.
Ngen will find all of the static dependence of the main assembly and compile them all in a low-level images. These images will be stored in cache of assemblies (GAC), thereby it is possible to reduce application load time.
How can I use C# to write a gadget in Windows 7?
Is it possible?
http://www.codeproject.com/KB/gadgets/CPRepWindowsGadget.aspx
And a search on codeproject shows even more: http://www.codeproject.com/search.aspx?q=gadget&sbo=kw
Is Sidebar gadgets what you are looking for?
Have a look at this Silverlight trick!
Assuming that "Windows Sidebar Gadgets" are being talked about, this is not possible to do directly. However there are some work-abouts (none of which are supported by Microsoft):
Use Silverlight. However, as I recall, the background can't be "painted transparent" and this will not work with a 64-bit IE (the IE running gadgets isn't always 32-bit by default) as there is no 64-bit Silverlight. This is the same problem plaguing sidebar gadgets that use Flash. (Like Pandora, one could require avid users to launch the 32-bit version of sidebar.exe).
Wrap the gadget window. I started work on a project like this that allowed WPF (in a separate process) to "overlay" the gadget window -- started via COM. Avoids 32/64-bit issues (actually, doesn't matter since it's in a separate process and is CLR, not Silverlight). Some issues with default gadget border, sizing, properties, etc. Concept work only.
Use an embedded HTA to launch a 32-bit IE and grab that handle (can then use/embedd Silverlight if launched the 32-bit version). I didn't have success with this, but it "should work".
Use a converter like Script# -- write in C#, "compile" to JavaScript.
Happy coding.
I want to aggregate and rearrange the displays of multiple programs into one. Is there a way, in Windows and preferably C#, to screenshot-to-texture from other running applications?
In Vista and Windows 7, with DWM (i.e. Aero-Glass) enabled, the DWM Thumbnails API provides a good way to do this with minimal resource usage and lag.
If you need to support older versions of Windows, or newer versions but where DWM may not be enabled/available, then I think you might have to copy out of the screen/window DCs in a loop and paint what you obtain into your own window, which will be very slow and probably use a lot of CPU.
(If you want to get really advanced, you might be able to write some kind of mirror display driver or something, but that's very complex.)
Using ExternalInterface in AS3 is it possible to call OS (C#?) functions within XP?
Example: Set the desktop background to a image supplied by a flash app?
If it is possible would it be different calls when applied to different OS. And what about cross over the Mac?
Any information would be great
Thanks
If you're launching the swf from within a C# app, external interface will do just fine. Nothing will change on the flash side, but you'll need to go through a couple hoops to get it to work in C#. It's not as simple as AMF or External Interface to JS.
All the communications to C# get converted to XML describing the data, and you've gotta write XML to send back to flash. Other than that though, its relativly simple.
Here's some info on how to do it. The AS portion is Flash 8/AS2, but the C# portion should say the same.
When working with Flash from a webpage or as a desktop app, you are limited to a small security sandbox and you will not be able to make any relevant OS call. I thought that switching to AIR would give the developper more flexibility but it doesn't seem correct either. From "The Pros and Cons of Adobe Air":
AIR apps have
file access, clipboard access, support
multiple windows, support drag and
drop, and can trigger notifications
(toast in Windows). If you app needs
to interact with the desktop in other
ways, the chances are that AIR is not
suitable. For example, there is no
access to COM automation, and no way
to execute external applications. The
reason is to maintain cross-platform
compatibility. That's a worthy goal,
but it would be good to have a way out
of the sandbox. Unlike Java or .NET,
you cannot extend AIR with custom
native code libraries. Nor can you
call operating system APIs.
As Alex Jillard commented, if your swf is called inside a C# desktop application, you should be able to access more OS funcionalities although I'm not sure how.
You could use as already mentioned AIR. Another idea would be to use HippoHX (I haven't written this, the similarity with my username is just coincidence). It runs on top of the NekoVM and gives you unrestricted (so no limitations like in AIR ) access to the system.
Sometimes I create some quick personal projects using C# with Windows Forms or WPF. I have noticed that managed applications can take 2x or 3x times longer to start compared with native applications.
I have written a "Quick Notes" application, however it isn't very "quick". :-(
What are some techniques to speed up the initialization of Windows Forms/WPF applications?
Check out NGen
Also, if you are loading lots of data on load, move it to another thread and show an indicator or something (while it's loading) so at least the form pops up quickly, even if it takes a little longer for the actual data to load.
.NET 3.5 SP1 does tend to make start up a little quicker. Also see a series of blog posts on putting up a splash screen (in native C++) while starting the WPF application at the Logos Blog.
.NET 3.5 SP1 also now includes the ability to create a fast SplashScreen without using C++
You might also want to consider moving processing off to worker threads. When your app starts load the root UI, but not the data - rather load the data async (and create pad windows etc. as each data item comes in).
.NET applications made for .NET 3.0 or later work much better on newer versions of Windows, Windows Vista, Windows 7, etc. I think in a few years time the difference between managed and unmanaged code in terms of performance will unnoticeable.