Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / Win32

Inter-Process Communication (IPC) Introduction and Sample Code

Rate me:
Please Sign up or sign in to vote.
4.91/5 (57 votes)
19 Dec 2009Ms-PL8 min read 251.3K   12.2K   195  
This article will cover general IPC technologies in All-In-One Code Framework. The IPC technologies include Named Pipes, File Mapping, MailSlot, etc.
/****************************** Module Header ******************************\
* Module Name:	ClientActivatedObject.cs
* Project:		CSRemotingSharedLibrary
* Copyright (c) Microsoft Corporation.
* 
* ClientActivatedObject.cs defines a client-activated type for .NET Remoting.
* Client-activated objects are created by the server and their lifetime is 
* managed by the client. In contrast to server-activated objects, client-
* activated objects are created as soon as the client calls "new" or any 
* other object creation methods. Client-activated objects are specific to the 
* client, and objects are not shared among different clients; object instance 
* exists until the lease expires or the client destroys the object. 
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* History:
* * 3/7/2009 10:50 PM Jialiang Ge Created
\***************************************************************************/

#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
#endregion


namespace RemotingShared
{
    /// <summary>
    /// A client-activated type for .NET Remoting.
    /// </summary>
    public class ClientActivatedObject : MarshalByRefObject
    {
        protected float fField;

        /// <summary>
        /// A float property.
        /// </summary>
        public float FloatProperty
        {
            get { return this.fField; }
            set { this.fField = value; }
        }

        /// <summary>
        /// Get the type of the remote object. 
        /// ClientActivatedObject or ServerActivatedObject
        /// </summary>
        /// <returns></returns>
        public virtual string GetRemoteObjectType()
        {
            return "ClientActivatedObject";
        }

        /// <summary>
        /// Get the current process ID and thread ID.
        /// </summary>
        /// <param name="processId">current process ID</param>
        /// <param name="threadId">current thread ID</param>
        public void GetProcessThreadID(out uint processId, out uint threadId)
        {
            processId = GetCurrentProcessId();
            threadId = GetCurrentThreadId();
        }

        /// <summary>
        /// Get current thread ID.
        /// </summary>
        /// <returns></returns>
        [DllImport("kernel32.dll")]
        internal static extern uint GetCurrentThreadId();

        /// <summary>
        /// Get current process ID.
        /// </summary>
        [DllImport("kernel32.dll")]
        internal static extern uint GetCurrentProcessId();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
China China
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

Comments and Discussions