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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using FObjBase;
using FObjSysTest.Client;
using FObjSysTest.IService;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Client_ConsoleApp
{
class Program
{
static ObjAServiceClient objaClient;
static void Main(string[] args)
{
objaClient = new ObjAServiceClient(0x12345600);
FObjSys.Current.Connect_to_Another_OBJSys(
new IPEndPoint(IPAddress.Loopback, 12345), objaClient.ID);
objaClient.PropertyChanged += ObjaClient_PropertyChanged;
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 10;
timer.AutoReset = true;
timer.Elapsed += Timer_Elapsed;
timer.Start();
System.Timers.Timer timer2 = new System.Timers.Timer();
timer2.Interval = 1000;
timer2.AutoReset = true;
timer2.Elapsed += Timer2_Elapsed;
//timer2.Start();
Console.WriteLine("client --------------------");
while (true)
{
string cmd = Console.ReadLine();
Console.WriteLine($"cmd = {cmd}");
if (cmd == "SetNumbers")
{
double[] numbers = new double[20000];
for (int i = 0; i < numbers.Count(); i++)
numbers[i] = i;
objaClient.Numbers = numbers;
objaClient.Apply();
}
else if (cmd == "GetNumbers")
{
Timer2_Elapsed(null, null);
}
}
}
static double tick = 0;
static Stopwatch stopwatch = new Stopwatch();
private static void Timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (stopwatch.IsRunning)
return;
stopwatch.Restart();
objaClient.GetNumbers(tick++, (obj, retdata) =>
{
stopwatch.Stop();
var reponse = retdata as Pack_CallGetNumbersReponse;
Console.WriteLine($"GetNumbers Reponse reponse.numbers.Count()={reponse.numbers.Count()} stopwatch.ElapsedMilliseconds = {stopwatch.ElapsedMilliseconds}ms");
}, null);
}
static bool mylock;
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (mylock != true)//不能让它能重入
{
mylock = true;
FObjBase.PollModule.Current.OnPoll();
mylock = false;
}
}
private static void ObjaClient_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Console.WriteLine($"e.PropertyName = {e.PropertyName}");
if (e.PropertyName == "Numbers")
{
Console.WriteLine($"objaClient.Numbers.Count() = {objaClient.Numbers.Count()}");
}
}
}
}