HOW TO: ??????? ????? ???????? ????? ?? Visual Studio .NET

?????? ????????? ?????? ?????????
???? ???????: 318185 - ??? ???????? ???? ????? ????? ??? ???????.
??? ????? ??? ???????. ????? "??? ??" ??? ??? ??????? ??? ????.
????? ???? | ?? ????

?? ??? ??????

??????

?????? ??? ???? ???? ????? ?????? ????? .NET ????? ??? ????, ????? ? ????? ??????? ???????? ???? ??????? ?? "?????" COM +.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • Microsoft Windows 2000 Professional ?? ???? ??????? Microsoft Windows 2000 Server ? Microsoft Windows XP Professional ?? Microsoft Windows XP Server.
  • ???? ??? Microsoft .NET.
  • Microsoft Visual Studio .NET.
  • Microsoft Visual C# .NET.
  • Microsoft COM +.
????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • COM ?????? ???????.
  • ?????? ?????? ??????? ???????? ??????.

????? ????? .NET ??? ??????? Coupled ????? ???????????

???? ??????? ?????? ????? .NET ????? ??? ????? ?? ????? ???????? ???? ??????? ?? "?????" COM + ? ????? ?? ????:
  1. ???? ??? ???? ???? ??? ???????? ???? ??? Microsoft Visual Studio .NET ? ?? ???? ??? Microsoft Visual Studio .NET.
  2. ???? ??? ????? ????.
  3. ?? ????? Project ? ???? ??? Visual C# ????????.
  4. ?? ????? ? ??? ????? Windows.
  5. ?? ?????? ?????? ???? HowToLCE ??? ?? ???? ??? ?????.

    ???? ???? ?? ???? ????? ??? shell ??????? ????? Windows.
  6. ????? "????? ??????" ????? ??? "??????? ??????" ?????? "?" ??????? "?" ????? ???????? ?????? ??????. ?? ??????? ???? ??? ??? ????? Project ?? ???? ??? ????? ????.
  7. ?? ????? Project ? ???? ??? Visual C# ????????.
  8. ?? ????? ? ???? ??? ????? ??????.
  9. ?? ?????? ?????? ???? ClassLibLCE ??? ?? ???? ??? ?????.
  10. ?? "?????? ??????" ??? ClassLibLCE ???? ??? ?????? ?????? ??? ????? ??? ?? ???? ??? ????? ????.
  11. ??? ????? ??????? .NET ??? ????? ? ???? ??? System.EnterpriseServices ?? ???? ??? ?????. ???? ??? ?????.
  12. ????? ??????? ??????? ??????? ?? ???? ????? Class1.cs ?????? ??? ?????? ?? ?????? ????? ???:
    using System.EnterpriseServices;
    using System.Diagnostics;
    						
    ??? ????? ???? ????? ?????? "? ???? ????? .NET. ??? ????? ???? ????? ?????? ??? "?????" COM + ???? "??????" ? "??????? ????? ?? EnterpriseServices.ServicedComponents().
  13. ?? ?????? ??????? ??? ?????? ??? ?????. ?? ??? Class1.cs ?????? ???????? ???????? ??????? ??? ????? ?????? Class1:
    public interface IEvSink
    {
    	void OnEvent1();
    	void OnEvent2();
    }
    					
  14. ??????? ????? ?????? Class1 ???????? ???????? ??????? ???? Publisher:
    [EventClass]
    public class MyPublisher : ServicedComponent, IEvSink
    {
    	public MyPublisher()
    	{
    	// 
    	// TODO: Add constructor logic here.
    	// 
    	}
    	public void OnEvent1()
    	{}	
    	public void OnEvent2()
    	{}
    	}
    						
    ???? ????? ????? ??????? ?? ????? [EventClass]. ??? ????? ?????. ???? ?????? "?????" COM + ?? ??? ????? ??????? ??????? ??? ?????? subscriber(s) ????? ??. ??? ????? ??? ???? ????????? ???????? ?? ??? ??????? ????? ???? ?? ????????? ?????? ??? ??? MyPublisher. ????? ???? ??? ?????? ??????? ??? Publisher ??????? ??? "?????" COM + ?????? ??? ??? ????? [EventClass]. ????? ??? ??? ?????? ????? ?? ??????? subscriber(s). ???? ?? ????? ?? ??????? ??????? ?? "?????" COM + ???? ??????? ???? ?????? ????? IEvSink ??????? ?? ??????.
  15. ???? ???????? ?? ????????? ???????? ?? "????? ??????" ???????. ????? ??? ????? ????? ????? ?????? ??????. ?? ??? ??????? ???? ????? ????? ?? ??? ??????? ?????? ?????? ??????? ??? ??????? ??? ????? ????????. ?? ?????? ????????? ???????? ??????? ??? ??? MyPublisher:
    public class MySubscriber : ServicedComponent, IEvSink
    {
    	EventLog ev = new EventLog("Application");
    
    	public void OnEvent1()
    	{
    		ev.Source = "ClassLibLCE";
    		ev.WriteEntry("OnEvent1 Fired");
    	}
    
    	public void OnEvent2()
    	{
    		ev.Source = "ClassLibLCE";
    		ev.WriteEntry("OnEvent2 Fired");
    	}
    }
    					
  16. ???????? ??????? ????? ?? "????? ??????" ??????? ??? ????. ?????? ??? ???????? ??? ??????? ?????? ?????? SN (Sn.exe). ??? ????? ?? ???? \bin ??? ?? ????? .NET Framework ??????? ????? "????? ?????? (SDK). ???? SN ???? ??? ?????????. ???? ??? ??????? ?????? ???? ?????? ??????:
    ???? sn "C:\%DirectoryToPlaceKey%\%KeyName%.snk"
  17. ????? ??? ????? ?? ???? ??????? Visual Studio .NET. ???? ??? ???? ? ???? ??? ??????? ? ???? ??? Microsoft Visual Studio .NET ? ??? ??? ????? .NET Visual Studio ?? ???? ??? ???? ??????? .NET Visual Studio. ?? ???? ???????? ???? ?? ???:
    ???? sn "C:\ClassLibLCE\key.snk"
    ??? ?? ??? ??????? "????? ??????" ?? ??? ?????? ????? ?????? ??? ??? ???? ??????? ??????? "????? ??????".

    ??? ????? ?????. ?????? ?? ???, ?? "?????? ??????" ? ??? ClassLibLCE ?? ???? ??? ???? "????? ???? ???????" ??? ???? ????? ?????? ??????.

    ???? ?????? key.snk ??? ClassLibLCE.
  18. ????? ??? ???????? ??? ??? ??????? ??? ???????? ?? ??????? "????? ??????" ??? ?. ?? "?????? ??????" ??? ClassLibLCE ???? ????? ??????? ??? AssemblyInfo.cs. ?? AssemblyKeyFile ???? ?? ??? ??? ?????? ?????? ????????:
    "..\\..\\key.snk"
  19. ????? ???????? ???????? ?????? ???? ??????? ?? ???? ???? ????? ????? ????? Windows ??? "????? ??????". ???? ?? ??? ??????? ??? ?????? ????? ????????. ???? ???? ????? ?? "???? ??????". ????? ????? ????????.
    1. ?? "?????? ??????" ??? HowToLCE ???? ??? ?????? ?????? ??? ????? ?? ???? ??? ????? ???? ??????? ????????.
    2. ?? ????? ??????? .NET ? ???? ??? System.EnterpriseServices.
    3. ?? ????? ??????? "????????" ? ???? ??? ClassLibLCE.
    4. ???? ??? ?????.
    5. ???? ??? ?????.

      ???? ??????? System.EnterpriseServices ? ClassLibLCE ???????? ??? ???????.
  20. ?? ???? ????????? ????????? ???? ??? ????? ??????? Form1.cs [?????] ????? ??????? ?? ???? ??? ??????? ????? ????? ??? Form1_Load. ????? ????????? ???????? ??????? ????? ????? ???.

    ???? ?? ???? ?????. ?????? ??? ?? ??? ????? "????? ??????". ??? ????????? ??? ????? ???. ????????? ?????? ??????? ??????.
    // Section #1
    // Register Class Library as a COM+ application.
        ClassLibLCE.MySubscriber l = new
        ClassLibLCE.MySubscriber ();
    
    // Section #2
    //  Call Events on Publisher
    //  ClassLibLCE.MyPublisher l = new ClassLibLCE.MyPublisher();
    //  l.OnEvent1();
    //  l.OnEvent2();
    					
  21. ???? F5 ?????? ??????? ?? ???????? "????? ??????".

    ???? ??? ??????? ?? ?????? ??? ???? ??? ???? ??? ?? "?????" COM +. ??? ????? ??????? ??????. ??? ?? ???? ????? ????? ????? .NET ???? ??? ???? ????????? ?? "?????" COM +. ??? ????? ?? ???? ????? ???? ??????? ??? ?? ??? ????? ????????? ?????? ???????? ???? ??????. ??? ?? ??? ??? ?????????? ????? ???????? ??????? ????? ?? ???? ?????? ??? ????????? ??????? ?????? ???, ????? ????? ????? ???????? ?????? ???????? Regasm.exe ?????? ??? ??? ??? ???????.
  22. ????? ?????? ???????? "????? ????????".

    ?? ???? ????? ????????? ???????? ???? ?? .NET ??????? 1.0. ???? ????? ?????? ???? ?????? ?????? ????? ?????? ???????? "????? ????????": ??? ???? ?????? ? ???? ????? ??????? ??? ????? ?????? ?? ???? ????? ??????? ??? ????? ????????.

    ??????: ??? ????? ????? ????? ????????? ???????? ?????? ??????? ??????? ???????? "COM + 1.0 ????? ?????". ?????? ??? ??????? ??????? ??? ??????? ????? ?? "?????? ????????".
  23. ?? ?????? "????? ????????". ?? ?????? Computers. ?? ?????? ???? ?????????. ?? ?????? ??????? COM +. ?? ?????? ClassLibLCE. ?? ?????? ????????. ?? ?????? ClassLibLCE.MySubscriber.
  24. ???? ??? ?????? ?????? ??? ?????? ???????? ? ??? ??? ???? ?? ???? ??? ??????.
  25. ?? COM + "???????? ??????? ?????" ???? ??? ??????. ??? ?????? ???????? ????? IEvSink. ???? ??? ??????.
  26. ?? ?????? "????? ??? ?????" ? ???? ??? ClassLibLCE.MyPublisher. (??? ?? ????? ???? ?? ????? ??? ????? [EventClass].) ???? ??? ??????.
  27. ???? ????? ???? ???? ???????? ?? ???? ?????? ???? ???????? ????? ??? ???????? ??????. ???? ??? ??????. ???? ??? ?????.

??? ???? Class1.cs

using System;
using System.EnterpriseServices;
using System.Diagnostics;

namespace ClassLibLCE
{
       /// <summary>
       /// Summary description for Class1.
       /// </summary>
       [EventClass]
       public class MyPublisher : ServicedComponent, IEvSink
       {
	     public MyPublisher()
	     {
	     // 
	     // TODO: Add constructor logic here.
	     // 
	     }

	     public void OnEvent1()
	     {}	

	     public void OnEvent2()
	     {}
	     }

	     public class MySubscriber : ServicedComponent, IEvSink
	     {
		EventLog ev = new EventLog("Application");

		public void OnEvent1()
		{
			ev.Source = "ClassLibLCE";
			ev.WriteEntry("OnEvent1 Fired");
		}

		public void OnEvent2()
		{
			ev.Source = "ClassLibLCE";
			ev.WriteEntry("OnEvent2 Fired");
		}
	}

	public interface IEvSink
	{
		void OnEvent1();
		void OnEvent2();
	}
}
				

??? ???? AssemblyInfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;

// 
// General information about an assembly is controlled through the 
// following set of attributes. Change these attribute values to modify
// the information associated with an assembly.
// 
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]		

// 
// Version information for an assembly includes the following four 
// values:
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
// 
// You can specify all the values or you can use the default Revision and 
// Build Numbers by using the '*', similar to this:

[assembly: AssemblyVersion("1.0.*")]

// 
// To sign your assembly, specify a key to use. For more 
// information about assembly signing, see the Microsoft .NET Framework 
// documentation.
// 
// Use the following attributes to control which key is used for signing. 
// 
// NOTES: 
//   (*) If no key is specified, the assembly is not signed.
//   (*) KeyName refers to a key that is installed in the Crypto Service
//       Provider (CSP) on your computer. KeyFile refers to a file that 
//       contains a key.
//   (*) If the KeyFile and the KeyName values are both specified, the 
//       following processing occurs:
//       (1) If the KeyName is found in the CSP, that key is used.
//       (2) If the KeyName does not exist and the KeyFile does exist, the 
//           key in the KeyFile is installed into the CSP and used.
//   (*) To create a KeyFile, you can use the Sn.exe (Strong Name) 
//       tool. When specifying the KeyFile, the location of the KeyFile 
//       must be relative to the project output folder which is
//       %Project Directory%\obj\<configuration>. For example, if your 
//       KeyFile is located in the project folder, specify the 
//       AssemblyKeyFile attribute as 
//          [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
//   (*) Delay Signing is an advanced option. For more information, see the 
//       Microsoft .NET Framework documentation.
// 
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("..\\..\\key.snk")]
[assembly: AssemblyKeyName("")]
				

??? ???? Form1.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace HowToLCE
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			// 
			// Required for Windows Form Designer support.
			// 
			InitializeComponent();

			// 
			// TODO: Add any constructor code after the
			// InitializeComponent call.
			// 
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support; do not modify
		/// the contents of this method with the Code Editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Section #1
			// Register Class Library as a COM+ application.
//			ClassLibLCE.MySubscriber l = new ClassLibLCE.MySubscriber();

			//Section #2
			// Call Events on Publisher.
				ClassLibLCE.MySubscriber l = new ClassLibLCE.MySubscriber();
						l.OnEvent1();
						l.OnEvent2();
		}
	}
}
				

???? ?? ??? Works

  1. ?? ???? ???? ????????? ???????? ??????? ????????? ???????? ?? ???? # 1 ????? Form1.cs ?? uncomment ????????? ???????? ?? ?????? # 2.
  2. ?? ?????? ????? ???????? ??????? HowToLCE ???. ?????? ????? ???? ??? ????? ????? ??????? ????. ?? ?????? ????? ???? ???????? ?????ClassLibLCE. ???? ??? ?????.
  3. ???? F5 ?????? ??????? ?? ??? ???????.
  4. ??? ????? ??????? ??????.
  5. ???? CTRL + ALT + S ?????? "?????? ??????". ????? ????????. ?? ?????? computer name. ?? ?????? ????? ???????. ?? ?????? ?????. ?? ?????? ClassLibLCE.

    ???? ??????? ??? ???????.

??????? ??????? ????????

  1. ????? ??? ??????? ??????? ????????? ?? "?????? ??????".
  2. ??? ??? ?????? ??????? ??? "????? ??????" ??? ????? ???? ????????? ??????? ?? ?? ?????? ????? "????? ??????" ??? ?????? ????? ??????? ?????? ????? ??????. ?????? ??? ??? ??????? ??? ???????? ???????:
    • ???? ??? ?????? ?????? ??? ?????? ?? ????? ???????? "? ?? ???? ??? ?????.

      - ?? -
    • ??? ?????? ??? ??? ???? ????? ??????? ???? ??? ????????? ???????? ?????? ??.



?????

?????? ??? ??????? ?????? ??? ????? coupled ???????? ?? ?????? ???? Microsoft ?????? ??? ?????:
Using Loosely Coupled Events
?????? ??? ??????? ?????? ??? ????? ????? + COM ?????? ??????? ????? ?? ?????? ???? Microsoft ?????? ??? ?????:

???????

???? ???????: 318185 - ????? ??? ??????: 28/???? ??????/1435 - ??????: 3.3
????? ???
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft .NET Framework Class Libraries 1.0
????? ??????: 
kbnosurvey kbarchive kbmt kbhowtomaster KB318185 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????318185

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com