-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoSpecifiedTargetFunctions.cs
More file actions
65 lines (54 loc) · 1.79 KB
/
DemoSpecifiedTargetFunctions.cs
File metadata and controls
65 lines (54 loc) · 1.79 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Windows.Forms;
using SynchronousMessageSystem;
namespace DemoApplication;
public partial class DemoSpecifiedTargetFunctions : Form
{
private ActorSystem ActorSystem { get; }
public DemoSpecifiedTargetFunctions()
{
InitializeComponent();
// 1. Create the actor system.
ActorSystem = new ActorSystem();
}
private void button1_Click(object sender, EventArgs e)
{
// 3. Tell the first actor to talk to the second actor. You could keep a reference in the form.
ActorSystem.GetActor<Actor1B>()!.SendMessage();
}
private void DemoSpecifiedTargetFunctions_Load(object sender, EventArgs e)
{
// 2. Create the actors.
ActorSystem.AddActor(new Actor1B());
ActorSystem.AddActor(new Actor2B());
}
}
public class Actor1B : Actor
{
public void SendMessage()
{
// 4. Send a string and an int.
Talk(typeof(Actor2B), "Hello!");
Talk(typeof(Actor2B), 55);
}
public override void Other(Actor sender, ActorMatch? address, object message)
{
}
}
public class Actor2B : Actor
{
public Actor2B()
{
//Configure to send strings to one function and ints to another.
MatchList.Add(new ActorMatch(typeof(string), I_accept_strings));
MatchList.Add(new ActorMatch(typeof(int), I_accept_ints));
}
// 5. Accept different types of messages.
public void I_accept_strings(Actor sender, ActorMatch address, object message) =>
MessageBox.Show((string)message, @"Got a string");
public void I_accept_ints(Actor sender, ActorMatch address, object message) =>
MessageBox.Show(((int)message).ToString(), @"Got an int");
public override void Other(Actor sender, ActorMatch? address, object message)
{
}
}