PowerSNMP for .NET CF
Start Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > Agent Class : Start Method




worker
AgentMessageReceived delegate specifying the function to execute.
state
Information to pass to the worker function; can be null.
Starts a worker thread on which the specified delegate is called each time a RequestMessage is received.

Syntax

Visual Basic (Declaration) 
Public Sub Start( _
   ByVal worker As AgentMessageReceived, _
   ByVal state As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As Agent
Dim worker As AgentMessageReceived
Dim state As Object
 
instance.Start(worker, state)
C# 
public void Start( 
   AgentMessageReceived worker,
   object state
)
Managed Extensions for C++ 
public: void Start( 
   AgentMessageReceived* worker,
   Object* state
) 
C++/CLI 
public:
void Start( 
   AgentMessageReceived^ worker,
   Object^ state
) 

Parameters

worker
AgentMessageReceived delegate specifying the function to execute.
state
Information to pass to the worker function; can be null.

Example

The following example demonstrates starting a simple agent supporting a MIB variable.
C#Copy Code
private void button1_Click(object sender, EventArgs e)
{
    //Add variable to agent
    agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace");
    agent1.Variables.Values.Add(agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace"));

    //Start listening for requests
    agent1.Start(agent1_MessageReceived, null);
}

private void agent1_MessageReceived(Agent agent, RequestMessage request, object state)
{
    //Create and send a response whenever a request is received
    agent1.Send(agent1.CreateDefaultResponse(request), request.Origin);
}
Visual BasicCopy Code
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    'Add variable to agent
    agent1.Variables.Values.Add(agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace"))

    'Start listening for requests
    agent1.Start(agent1_MessageReceived, Nothing)
End Sub

Private Sub agent1_MessageReceived(ByVal agent As Agent, ByVal request As RequestMessage, ByVal state As Object)
    'Create and send a response whenever a request is received
    agent1.Send(agent1.CreateDefaultResponse(request), request.Origin)
End Sub

Remarks

This method provides a convenient means for receiving SNMP request messages on a worker thread, and should be used to receive and respond to SNMP requests.

The state parameter can be null when no state information is passed to the worker delegate function.

Unhandled exceptions occurring on the worker thread are caught and reported in the ComponentBase.Error event.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.