Welcome to MSDN Blogs Sign in | Join | Help

Process Creation and Coordination

In some previous posts (Out of Process IPC/TCP Remoting code, .Net Remoting (AppDomains, Out of Process, Two Way, etc..)) I showed some sample code using .Net remoting over a process boundary. As a result, I received a few questions about the process creation and how to handle the process coordination (i.e., The Host/Master process waiting on the created process startup). I apologize to those who have been waiting for another sample on the subject, but I have been pretty busy as of late.

The attached sample code shows the following;

1.     How to ensure the Host Process waits on the new process creation.

a.     Previously I showed a simple *hack* where the created process sleeps for a while in order to let the process creation complete.

b.     A much cleaner and more reliable solution uses EventWaitHandle.

2.     The created Process runs until the Host Process is terminated or the Host terminates the new process.

a.     Previously I showed a simple *hack* where the created process does a Console.ReadLine() in order to halt code execution and thus cause process termination.

b.     I didn’t show an example of how the created process can shutdown in the event the Host process shuts down. This scenario covers orphaned processes.

c.     The solution: System.Diagnostics.Process.GetProcessById(HostPID).WaitForExit();

View Source for Host Process: Show Code ...

View Source for Created Process: Show Code ...

Posted by JackG | 0 Comments
Filed under: ,

Attachment(s): WaitForProcessStartup.zip

RTM of Visual Studio 2008 and .NET Framework 3.5 SP1 (Client App Deployment)

I wanted to thank all the ISV's, VAR's, and SI's I have spoken with and those who have replied to my requests for soliciting feedback on Client Application Development (e.g., Software as a Service (SaaS) and Rich Internet Applications (RIA)).

This release has a number of significant features and bug fixes.

The RTM announcement may be found here.

Here is a direct link to the Microsoft .Net Framework 3.5 SP1.

Here is a link to Scott Guthrie's blog discussing this release when it was in Beta.

I'm very happy to inform you that your feedback played a significant role in this release, which includes -

"New Breakthroughs for Developing and Deploying Client Applications

The .NET Framework 3.5 SP1 includes the new .NET Framework Client Profile -- the fastest and easiest way to deploy applications for Windows. With .NET Framework 3.5 SP1 and the .NET Framework Client Profile, developers can more easily deploy client applications thanks to an 86.5 percent reduction (197 MB to 26.5 MB) in .NET Framework size. This means that end users will be able to download and install Windows-based applications significantly faster than before. The .NET Framework Client Profile also makes it possible to extend the improved download and installation experience to existing .NET applications.

Developers now can quickly and simply deploy new and existing rich-client applications to a broader audience."

 

Silverlight 2, Beta 2 and the 2008 Olympics

Some time ago I wrote a post about the announced Silverlight 2 product.

While I received a number of favorable comments, I also received some skepticism. We have been working hard on delivering on our goals in the form of providing an amazing media experience for the 2008 Olympics. Here is a link to the NBC Olympic site where you can see the implementation of Silverlight 2, Beta2.

I found the web site (http://www.nbcolympics.com/video) experience to be incredible! I only wish I had the equivalent on my TV.

I hope those who were skeptical, now feel more confident in our delivery. Yep, it's still a Beta (2) but running the Olympics on our breadth of technology should give you a higher level of confidence. Enjoy.

Posted by JackG | 2 Comments
Filed under:

Configuring Visual Studio to Debug .NET Framework Source Code

Earlier I posted a link to the announcement on ScottGu's blog about the framework source availiability for debugging. I wanted to follow-up with my experience using the reference source.

I found the installation instructions on "Configuring Visual Studio to Debug .NET Framework Source Code" on Shawn Burke's blog. I assume there is some official MS site for these instructions but I didn't look very hard. If anyone knows the link please let us know. The installation worked great on my Vista laptop with VS 2008. I did notice that much of the Orcas (i.e., 3.5) BCL has yet to be published. Unfortunately this includes the Managed AddIn Framework (MAF, System.AddIn*) source. I am following up on the Orcas release and I will let you know when it gets published. Enjoy! JackG

Extensibility; Clients and Services calling each other

In this post I will be showing sample code (also found on our CodePlex site) as well as an execution sequence diagram. I will show sample code addressing some frequently asked questions; A Host calling AddIn services, AddIns calling (aka. Automation) a Host, AddIns calling AddIns, Managing AddIns (utilizing LINQ), which assemblies are loaded (Per AD and utilizing direct connect), etc…

1.     A sample Host application that supports calls from the AddIn (aka., Automation) to the Host.

a.     In the past we have shown the Host calling into the AddIn (Sample code), which happens naturally via System.AddIn activation of the AddIn. In other words, the activation of an AddIn allows the Host to call through to the AddIn.

b.     We have shown the *pipeline* allowing the AddIn to automate the Host (Sample code).

                                          i.    As a result of several requests, this is a sample solution showing an end-to-end solution that includes the Host, Pipeline, and AddIn.

c.     In the past I have shown sample code using pure remoting (i.e., No System.AddIn*) for two-way remoting / bi-directional calls (i.e., Host Automation) but now I will show the equivalent using MAF (i.e., Managed AddIn Framework).

Extensibility; Clients and Services calling each other

2.     I am including a Sequence diagram that ties to the Sample App source code showing;

a.     AddIn Discovery, Qualification, Activation, AddIn calls into the Host (aka., Host Automation), AddIns requesting and calling other AddIn services (i.e., Client/Services).

 Sequence diagram of Clients and Services calling each other

3.     Isolation - AppDomains and AddIns/Assemblies activated within each, understanding Activation optimization (i.e., Direct Connect forgoing Isolation), and unloadability (i.e., which assemblies/Types are loaded/unloadable).

4.     Using LINQ to help you manage AddIns.

5.     The benefits of having Adapters, whereby you have code running in the locality of an AppDomain. This is also an example aiding in understanding MarshalByRef (MBRO). 

a.     See List<string> GetASMInAppDomain(string AppDomainName) in HostHelper.cs for comments on the problem and the solution.

6.     New features we included in the latest features we added to the VS2008 3.5 release.

a.     Direct connect Optimization. We have received a few questions on this feature and as such I wanted to clarify the implementation. 

                                          i.    You must enable DirectConnect

1.     AddInToken.EnableDirectConnect = true;

                                         ii.    Our Activate method makes it easy to create an Add-in in a new AppDomain and as a result people are forgetting to pass in an existing AppDomain to the Activate method.

1.     HAV = tokens[i].Activate<IAuthProvider>(AppDomain.CurrentDomain);

                                        iii.    Although we do not instantiate the Adapters we still require them to be defined in the pipeline folders.  As some have pointed out, this may be counter-intuitive.  We took this approach in order to guide you toward the right design (i.e., support for isolation and version resilience) going forward.

                                        iv.    Your Host view of AddIn and AddIn view of Host types respectively, must be the same type (i.e., in the same assembly).

1.     In my sample code I list the assemblies in a selected AppDomain so you can see what is loaded.  In the direct connect scenario you should not see the Adapter assemblies loaded in the AppDomain. 

b.     [ActivatableAs] Attribute enables AddIn side, View Type hierarchies. 

                                          i.    I created an Abstract base class (ABC) as the Base for my views and I marked the ABC with our new attribute [ActivatableAs] which tells us which Base type is used for activating the Addin.  The sample code shows how you can use Interfaces and Abstract Base Classes as views.  This also shows some of the differences between versioning an Interface (which would require casting over time or Adapting) and an Abstract Base Class which allows a little more flexibility in versioning due to its ability to have default implementations. Note that the CLR does not support multiple inheritance so using Abstract Base Classes should be carefully considered.

c.     Custom Qualification

                                          i.    Example of an Addin advertising its demand for activation in the Hosts default AppDomain. The Key/Value pair is nothing more than metadata you may use to suite any need your imagination allows.

d.     FindAddIn

                                          i.    There are a number of scenarios where you may not have a clean directory structure for Add-in’s, or you may not have write access to the Add-in store, or you may not know the location of the Add-in until runtime (e.g., Click-Once deployed Add-in’s), etc..

e.      AddIns calling AddIns

                                          i.    I will show one Add-in utilizing other AddIns that were instantiated by the Host. The AddIn consumer (Client) requests the List of other AddIns (Services) from the Host. This enables the AddIn to consume other services without having to do its own discovery and activation.

                                         ii.    This sample also shows the benefits of Adapter creation helper methods (AuthProviderHostAdapter) and the MAF support for passing Lists of reference types (CollectionAdapters.ToIListContract<> and CollectionAdapters.ToIListContract<>).

1.     For more on Value and Reference type behavior, check out these posts by TQ

a.     Are Arrays OK in Contracts?

b.     Reference vs. Value: Types, Passing and Marshalling

7.     Multiple Add-ins in a single Assembly

a.     Although this isn’t a new feature, I am frequently asked about how assemblies and pipeline segments should be factored (more on this later) and confusion over Add-ins and Assemblies.

                                          i.    Check out the DefaultAuthProvider.cs as an example.

Microsoft announcement of Silverlight 2 (Devices/RIA/Client)

Yesterday, Microsoft announced a significant technology advancement in Rich Internet Application (RIA) platform development.

This announcement was significant on many levels from my perspective. 

  1. It solidifies (beyond SL 1) the ability to use .Net to develop richer (beyond video and media) web client applications. As you may know, I have had strong opinions on the previous Web development experience (Thin Client - Web Clients).
  2. It clearly shows our effort in meeting customer demands to provide a continuum and compatibility of development environments from Devices to Web and Rich/Smart Client applications. Check out Scott Guthrie's blog post with sample code
  3. Providing VS designer support and very rich Expression Studio support for the above. This will further empower designers to build rich client applications with WPF and rich media/RIA experiences with Silverlight.

Check out the Mix08 site for more details, including the keynote.

Some of the coolest things I saw were:

  • The Hard Rock Café demo of zooming in and out of media images and retaining resolution. WPF rocks!
  • The upcoming Olympics media experience was unbelievable. The demo of multiple channels on the screen, the ability to rewind real time events and PIP (Picture In Picture). Unbelievable. Sniff, sniff, I miss my ability to do PIP on my TV. Sad that with High Def, etc... I had to give up on one of the coolest features I once had.
  • Silverlights ability to adjust the streaming experience based on my ever changing connectivity bandwidth was to cool for school.

One other note. I watched the keynote live from my desktop and I couldn't help but wonder how the audience could sit their so quietly when so many cool things were being shown on real bits. We aren't talking vapor or demo-ware here. I haven't been directly involved in the SL development effort and granted I work at Microsoft so I likely bring some bias, and I guess I am more excitable than your average person about where we landed on the ability to develop applications in a very compatible way from devices to Web to Rich Client applications (and maybe I had some influence) but can someone tell me why the audience was not as engaged. I mean, PIP - come on people, that's cool stuff! In any event, as a developer/consumer I am thrilled, as a contributor I am proud, and as a user I don't expect I will leave my DVI flat panel dual monitors during the Olympics.

I would love to get your thoughts on where we hit or missed the mark. Enjoy!

You asked for it (AddIn pipeline generator)

After all, our job is to make your life easier.  I have received a *lot* of requests for a tool that can generate the Add-In pipeline segments.  Ever since we mistakenly left comments in our MSDN articles code about the pipeline source being machine generated, some of you noticed that we may have been working on a tool.  Soooooo, as a continuation of Microsoft's open and transparent developer experience (see this link for .Net framework source code, and this link to view/file bugs, receive early drops, etc..) we just released our pipeline generation tool source code to the community!!! 

The tool generates source code as opposed to a binary (like tlbimp) so that you may alter the generated code.  You may have specific naming conventions, or you would like to contribute to the tools functionality, so you can now do so via Codeplex.  Here is a link to our Managed Extensibility and Add-In Framework source.  We are also adding our sample code from our Add-in team Blog so that we a consolidated source (pun intended).

You can't say I didn't get you anything for Christmas.  Have a great new year!  JackG

Winforms, WPF and AppDomain isolation

We just posted a solution to consider for the F.A.Q. of how to enable isolatable WinForms applications.  Check out this link.  This solution may be considered relative to my previous post and subsequent comments.  Note that WPF startup performance costs may be mitigated by applying the [LoaderOptimization(MultiDomainHost)] attribute to the main method.  This tells the loader that the app expects to load multiple AppDomains with similar code and thus should share the assembly images (WPF NGen images) between AppDomains.

 

Visual Studio 2008 and .NET Framework 3.5 RTM

It's official.  We have released to manufacturing.

I am personaly very excited about the Add-in addtions to the BCL, but you can also find over 250 new features in this release (e.g., LINQ).  Check out the new release here.

TechEd 2007 F.A.Q.

Hola!

I just returned from TechEd 2007 held in Barcelona, Spain. Barcelona is a beautiful city with incredible new and old architecture. The people are very friendly and even I was able to navigate the clean public transportation systems.  Yes, I am one of those people that get lost easily and never stop to ask for directions. I was surprisingly given a beautiful suite overlooking the Mediterranean at the Hilton Diagonal Mar hotel right next to the convention center. I would highly recommend the hotel! Ask for a suite above the 15th floor in order to take advantage of the 15th floor amenities!

I could go on and on about Barcelona, but I wanted to provide some links answering some of the F.A.Q.'s I received.

1.    Does the Add-In model support UI extensibility via WPF? Yes, check out my Channel 9 video, as well as the sample code.