Reworking our protocols. Client name now displayed in our clients tab.
2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.ServiceModel;
11 using System.ServiceModel.Channels;
12 using System.Diagnostics;
15 namespace SharpDisplayClient
17 public partial class MainForm : Form
24 InitializeComponent();
27 private void buttonSetText_Click(object sender, EventArgs e)
29 //iClient.SetText(0,"Top");
30 //iClient.SetText(1, "Bottom");
31 iClient.SetTexts(new string[] { iClient.Name, iClient.SessionId });
34 private void MainForm_Load(object sender, EventArgs e)
36 iCallback = new Callback(this);
37 //Instance context is then managed by our client class
38 InstanceContext instanceContext = new InstanceContext(iCallback);
39 iClient = new Client(instanceContext);
41 //Connect using unique name
42 //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
43 string name = "Client-" + (iClient.ClientCount() - 1);
44 iClient.SetName(name);
45 //Text = Text + ": " + name;
46 Text = "[[" + name + "]] " + iClient.SessionId;
52 public delegate void CloseConnectionDelegate();
53 public delegate void CloseDelegate();
58 public void CloseConnectionThreadSafe()
60 if (this.InvokeRequired)
62 //Not in the proper thread, invoke ourselves
63 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
64 this.Invoke(d, new object[] { });
68 //We are in the proper thread
71 Trace.TraceInformation("Closing client: " + iClient.SessionId);
73 Trace.TraceInformation("Closed client: " + iClient.SessionId);
84 public void CloseThreadSafe()
86 if (this.InvokeRequired)
88 //Not in the proper thread, invoke ourselves
89 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
90 this.Invoke(d, new object[] { });
94 //We are in the proper thread
100 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
102 CloseConnectionThreadSafe();
105 public bool IsClientReady()
107 return (iClient != null && iClient.State == CommunicationState.Opened);