Click here to Skip to main content
15,896,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.7K   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:	CSSimpleClass.cs
* Project:		CSClassLibrary
* Copyright (c) Microsoft Corporation.
* 
* This sample creates a class library of C# code and builds it as a .NET DLL 
* assembly that we can re-use in other projects. The process is .very
* straightforward.
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* History:
* * 1/10/2009 10:33 PM Jialiang Ge Created
\***************************************************************************/

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
#endregion


namespace CSClassLibrary
{
    public delegate 
    void PropertyChangingEventHandler(object NewValue, out bool Cancel);

    /// <summary>
    /// CSSimpleClass
    /// </summary>
    public class CSSimpleClass
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public CSSimpleClass()
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public CSSimpleClass(float fVal)
        {
            this.fField = fVal;
        }

        /// <summary>
        /// Static Field
        /// </summary>
        private static bool sbField;

        /// <summary>
        /// Static Property
        /// </summary>
        public static bool StaticBoolProperty
        {
            get { return sbField; }
            set { sbField = value; }
        }

        /// <summary>
        /// Static Method
        /// </summary>
        /// <returns></returns>
        public static string StaticMethod()
        {
            return "HelloWorld";
        }

        /// <summary>
        /// Instance Field
        /// </summary>
        private float fField = 0F;

        /// <summary>
        /// InstanceProperty
        /// </summary>
        public float FloatProperty
        {
            get { return fField; }
            set
            {
                // Fire the event FloatPropertyChanging
                bool cancel = false;
                if (FloatPropertyChanging != null)
                    FloatPropertyChanging(value, out cancel);

                if (!cancel) // If the change is not canceled
                    fField = value;
            }
        }

        /// <summary>
        /// Public Instance Method
        /// </summary>
        /// <param name="fVal"></param>
        /// <returns></returns>
        public float Increment(float fVal)
        {
            lock (this) // thread safe
            {
                return this.fField += fVal;
            }
        }

        /// <summary>
        /// Internal Instance Method
        /// </summary>
        /// <param name="fVal"></param>
        /// <returns></returns>
        internal float InternalIncrement(float fVal)
        {
            lock (this) // thread safe
            {
                return this.fField += fVal;
            }
        }

        /// <summary>
        /// Instance Event
        /// </summary>
        public event PropertyChangingEventHandler FloatPropertyChanging; 

    } // class CSSimpleClass
} // namespace CSClassLibrary

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