Home > Articles > Programming > C#

  • Print
  • + Share This
Like this article? We recommend

Putting It All Together

Let's now take a look at the last file of interest: Program.cs. Listing 8 illustrates the main program.

Listing 8 The Main Program

static void Main(string[] args)
{
// Instantiate an LSP
Lsp lsp = new Lsp("LSP123", 1, 5, "R2R3R4R5", 100, 150);
// Make sink object.
Console.WriteLine("Creating LSP event sink\n");
LspEventSink sink = new LspEventSink("Event sink");
// Attach the sink to the LSP.
Console.WriteLine("Attaching a sink to the LSP");
lsp.Attach(sink);
// Forward some blocks of data (to generate some events.)
Console.WriteLine("\n***** Forwarding data *****");
for (int i = 0; i < 3; i++)
lsp.ForwardSomeData(20);
Console.WriteLine("\n***** Forwarding more data *****");
for (int i = 0; i < 2; i++)
lsp.ForwardSomeData(20);
// Detach the sink from the LSP.
Console.WriteLine("Detaching a sink from the LSP");
lsp.Detach(sink);
Console.ReadLine(); }

Listing 8 illustrates the overall workflow from lsp and sink instantiation to lsp attachment to the sink followed by forwarding data and then finally lsp detachment.

  • + Share This
  • 🔖 Save To Your Account