-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoMutateReceiverList.cs
More file actions
68 lines (57 loc) · 1.96 KB
/
Copy pathDemoMutateReceiverList.cs
File metadata and controls
68 lines (57 loc) · 1.96 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
66
67
68
using System;
using System.Windows.Forms;
using SynchronousMessageSystem;
namespace DemoApplication;
public partial class DemoMutateReceiverList : Form
{
private ActorSystem ActorSystem { get; }
public DemoMutateReceiverList()
{
InitializeComponent();
// 1. Create the actor system.
ActorSystem = new ActorSystem();
}
private void button1_Click(object sender, EventArgs e)
{
// 5. Send a string to Actor2c. Click this button twice.
ActorSystem.GetActor<Actor1C>()!.SendMessage();
}
private void DemoMutateReceiverList_Load(object sender, EventArgs e)
{
// 2. Create the actors.
ActorSystem.AddActor(new Actor1C());
ActorSystem.AddActor(new Actor2C());
}
public class Actor1C : Actor
{
public void SendMessage()
{
Talk(typeof(Actor2C), "Hello!");
}
public override void Other(Actor sender, ActorMatch? address, object message)
{
}
}
public class Actor2C : Actor
{
public Actor2C()
{
// 3. Configure this actor to have the FirstTimeAStringArrives function to respond when strings are sent.
MatchList.Add(new ActorMatch(typeof(string), FirstTimeAStringArrives));
}
public void FirstTimeAStringArrives(Actor sender, ActorMatch address, object message)
{
// 4. reconfigure this actor to have the SecondTimeAStringArrives function to respond when strings are sent.
MessageBox.Show((string)message, @"First time");
MatchList.Clear();
MatchList.Add(new ActorMatch(typeof(string), SecondTimeAStringArrives));
}
public void SecondTimeAStringArrives(Actor sender, ActorMatch address, object message)
{
MessageBox.Show((string)message, @"Second time");
}
public override void Other(Actor sender, ActorMatch? address, object message)
{
}
}
}