Opening winforms FolderBrowserDialog via web socket connection from C# class library - winforms

I need to open a winforms FolderBrowserDialog from class library. We are calling the method via web socket from js and i need to open a FolderBrowserDialog in that method in order to get path and do some operations inside the folder. I tried both opening a new winform which contains a FolderBrowserDialog and FolderBrowserDialog without form but the form is freezing and doesnt response afer show or showdialog method. Is there a proper way to do it?
Information about the arcitechture: We have a .net web socket listener app and it is already running on the client machine. Frontend requets comes in to that app an it runs c# on the clients machine using reflection class and dlls on the client machine.

I stumbled upon this problem also and noticed that when in C# winforms FolderBrowserDialog doesn't work from a class that doesn't inherit from a Form.
I put the method which uses FolderBrowserDialog in a form which I knew will be open at the time, then saved handle to this form to a place accessible from my class (i.e. static class/DI injected service etc) and called my method through that proxy.

Related

Limitations of using WebBrowser control to create WPF apps [duplicate]

I've recently stumbled across WebBrowser WPF control. I am interested if there are any limitations when building user interfaces with HTML+CSS+JS and embedding them in WebBrowser.
So far I've successfully
intercepted HTML click events and handled them in C# using
[ComVisible(true)] class attribute
called JS script from C# using InvokeScript method.
InvokeScript also supports sending objects to the HTML/JS via parameters which faciliates two way communication.
Is there any reason for not using using WebBrowser to create simple apps? I am intersted in parts that absolutely need to be handled with some WPF code and cannot be bridged using WebBrowser.

How can I instantiate the window/view that implements Caliburn Micro's IShell interface inside an Outlook Task Pane

I have a desktop application that is based on the Caliburn Micro framework. Everything works great. Now I am trying to port the same app into Outlook as a plugin.
In the desktop app, based on an entry inside app.xaml, Caliburn knows where to find the bootstrapper and instantiates it.
In case of the Outlook plugin, I've created an overridden bootstrapper that I instantiate explicitly inside ThisAddIn.ThisAddIn_Startup(). This one of course does not use the Application object.
I can even invoke a particular view using code similar to this
var windowManager = IoC.Get<IWindowManager>();
windowManager.ShowDialog(new MyViewModel());
And that will cause the view associated with the view model to be shown in a modal window on top of Outlook (hence validating that Caliburn Micro is able to find a view from a view model inside my Outlook plugin)
What I haven't figured out how to do is instantiate the Shell so that I can start using its functionality.
My expectation was that since my bootstrapper derives from BootStrapper, and I have registered my shell view model implementation with the MEF container as exporting IShell, Caliburn will automatically instantiate the shell view model and start using it. That is not happening.
My goal is to get the shell loaded inside my plugin's task pane as the container for other views that I will be loading based on user actions.
Any ideas or tips on how I can get this to work? In general has anyone got a shell implementation loading inside an Outlook or Office plugin's task pane?
Thanks!
Do you mean instantiate via Bootstrapper<Shell>. This uses the Window Manager underneath but I don't think that extends to outlook. There is nothing stopping you using the same code above to initialize your shell manually, composition will handle the rest of the application.
IoC.Get, by default calls Activator.CreateInstance so it is possible your problem is with MEF. The method that drives opening the Shell DisplayRootViewFor() calls this line.
windowManager.ShowWindow(IoC.GetInstance(viewModelType, null), null, settings);
If MEF is not hooked up properly it will fail causing your shell not to load.

Make an single instance app and showing the MainWindow when another instance is launched in VB.NET with WPF

I am looking for a way to make my app running in a single instance mode and showing the MainWindow of the first instance when another instance is launched.
I do a quick search on the internet but I did'nt find anything to open the MainWindow of the first instance or it was for Windows Form not for WPF.
I am working in VB.Net with Framework 4 and WPF.
Thanks
I wrote up an article for Winforms a while back at http://www.thinqlinq.com/Post.aspx/Title/Single-Instance-Winform-Issue. With winforms you can use the MyApplication_StartupNextInstance event handler to intercept subsequent launch requests and redirect them (navigating back to the MainWindow?) Unfortunately, I don't see that StartupNextInstance is still available with WPF. Maybe the pre 2.0 sample I posted at http://web.archive.org/web/20060528010613/http://www.avbsg.net/Uploads/SingleInstanceVB.zip can give you an idea of how to do this with WPF. My blog post walks through the general steps that I used.

For a Silverlight app, what is the best way to load data from a service at startup?

I am fairly new to Silverlight. I have an application I'm working on that needs some data from the server before the user is can start working with the application. This data is accessible via a WCF service on the web server.
My question is this: what is the best way to go about getting this data at Silverlight applicaiton startup?
My thought it to create a static class with a static member that would hold the results and to make the WCF service call in the Application_Startup event handler. My concern is that if this call is made asynchronously, how can I be certain that the data will have been retrieved from the service prior to the user interacting with the application?
Thanks
The simplest way is to let the application start normally and use a BusyIndicator control to stop the user from interacting with the application.
You could call your service during startup and replace/disable the BusyIndicator control once the wcf call returns.
The following link has some good advices on starting up a Silverlight app:
http://blogs.msdn.com/b/slperf/archive/2010/08/13/silverlight-startup-best-practices.aspx
You need to remember that the Application_Startup method is actually loaded when the Silverlight percentage bar comes up, its is not until you get to:
this.RootVisual = new MainPage();
that you are able to put a busy indicator or actually visually show your application.
So what i would do is on the Async call back, i would then display:
this.RootVisual = new MainPage();
after you have recieved your data back.
The other comment talks about using a BusyIndicator, but you cant do that in the App.Xaml or App.Xaml.cs file, as at the point of time there is not main page yet.
Thanks

How to access web application class into silverlight application

I am beginner in silverlight..I have created a silverlight project. When a new silverlight project is created it is automatically creating a silverlight application and one web application. I have added a class in both applications. Now I want to access a method of web application class into silverlight application class. Is it possible? I have tried to add web application reference to silverlight but VS is not allowing. Is there any another way to do??
What you need is called WCF. A really simple tutorial that should get you going is found here: How to call WCF methods from Silverlight controls
Fundementally WCF allows the silverlight client to make method calls on a class instance hosted on the web site.
Yes it is possible, but not in the normal way. A Silverlight assembly can only reference another Silverlight assembly (this is a limitation of VS2008, i don't know if it has been changed in VS2010).
What you need to do is add an existing file to your Silverlight project, when the file browse dialog opens you navigate to the class file you want to reuse, but instead of just clicking the Add button, click on the little down arrow on the button and choose Add as link - now the file will "exist" in both projects and can be used in both.
If you are going to do this repeatedly though, you will want to move those shared class files out into a separate assembly, do a project reference from your web app, and have the equivalent Silverlight class library mirroring it (sharing the files as links), and then project reference that Silverlight class library from your Silverlight app.

Resources