Visual Basic (Declaration) | |
---|---|
Public Overloads Sub Start( _ ByVal worker As SlaveThreadStart, _ ByVal state As Object _ ) |
Visual Basic (Usage) | ![]() |
---|---|
Dim instance As Manager Dim worker As SlaveThreadStart Dim state As Object instance.Start(worker, state) |
C# | |
---|---|
public void Start( SlaveThreadStart worker, object state ) |
Managed Extensions for C++ | |
---|---|
public: void Start( SlaveThreadStart* worker, Object* state ) |
C++/CLI | |
---|---|
public: void Start( SlaveThreadStart^ worker, Object^ state ) |
Parameters
- worker
- SlaveThreadStart delegate specifying the method to execute.
- state
- Information to pass to the worker delegate method; can be null.
The following example demonstrates sending a Get request to an agent and receiving the response.
C# | ![]() |
---|---|
private void button1_Click(object sender, EventArgs e) { //Create and send request on a worker thread manager1.Start(manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact)); } private void manager1_SendGetRequest(Dart.Snmp.ManagerSlave slave, object state) { //Create Get Request GetMessage request = new GetMessage(); request.Community = "public"; request.Version = SnmpVersion.One; request.Variables.Add(state as Variable); //Send request and get response ResponseMessage response = slave.GetResponse(request, myAgentAddress); //Marshal message to the UI thread using the Message event manager1.Marshal(new ResponseMessage[] { response }, null); } private void manager1_Message(object sender, Dart.Snmp.MessageEventArgs e) { //Display info about the first variable in the response, and its value Variable var = e.Messages[0].Variables[0] as Variable; label1.Text = var.Definition.ToString() + var.Value.ToString(); } |
Visual Basic | ![]() |
---|---|
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) 'Create and send request on a worker thread manager1.Start(AddressOf manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact)) End Sub Private Sub manager1_SendGetRequest(ByVal slave As Dart.Snmp.ManagerSlave, ByVal state As Object) 'Create Get Request Dim request As GetMessage = New GetMessage() request.Community = "public" request.Version = SnmpVersion.One request.Variables.Add(CType(IIf(TypeOf state Is Variable, state, Nothing), Variable)) 'Send request and get response Dim response As ResponseMessage = slave.GetResponse(request, myAgentAddress) 'Marshal message to the UI thread using the Message event manager1.Marshal(New ResponseMessage() { response }, Nothing) End Sub Private Sub manager1_Message(ByVal sender As Object, ByVal e As Dart.Snmp.MessageEventArgs) 'Display info about the first variable in the response, and its value Dim var As Variable = CType(IIf(TypeOf e.Messages(0).Variables(0) Is Variable, e.Messages(0).Variables(0), Nothing), Variable) label1.Text = var.Definition.ToString() & var.Value.ToString() End Sub |
This method provides an easy means for executing blocking functions on multiple, concurrent worker threads. Applications should use this technique to execute processes (like a series of GetRequest methods) that would block the current thread. Typically, a complex application could contact several agents concurrently by running multiple requests on multiple threads.
Unhandled exceptions thrown on the worker thread are caught and reported by the ComponentBase.Error event.
Target Platforms: Microsoft .NET Framework 2.0