Home BigDipper Light: First Asynchronous Sample
Post
Cancel

BigDipper Light: First Asynchronous Sample

Microsoft invents a series of patterns for .NET asynchronous API design. However, no every pattern meet all requirements. For #SNMP, currently the Begin/End pattern is still the most suitable as it can be used in extension methods.

Today I built the first sample for our asynchronous API and soon detected a few issues. Luckily the issues were resolved in our latest change set (http://sharpsnmplib.codeplex.com/SourceControl/changeset/changes/faffeafa130c) and below is the sample code,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Net;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;

namespace TestAsyncGet
{
    class Program
    {
        static void Main(string[] args)
        {
            GetRequestMessage message = new GetRequestMessage(0,
                VersionCode.V1,
                new OctetString("public"),
                new List<Variable> {new Variable(new ObjectIdentifier("1.3.6.1.1.1.0"))});
            var endpoint = new IPEndPoint(IPAddress.Loopback, 161);
            message.BeginGetResponse(endpoint,
                new UserRegistry(),
                endpoint.GetSocket(),
                ar => {
                    var response = message.EndGetResponse(ar);
                    Console.WriteLine(response);
            });
            Console.Read();
        }
    }
}
This post is licensed under CC BY 4.0 by the author.
Advertisement

BigDipper Light: Asynchronous Calls Coming

Discussion on Open Source Licenses

Comments powered by Disqus.