Client/Client.cs
author sl
Thu, 14 Aug 2014 09:30:14 +0200
changeset 25 6f10207a89a8
parent 22 cac466b1b6e6
child 26 a6fb2b2f73b0
permissions -rw-r--r--
Fixing hang when closing server with live client due to client instance context
throwing an exception when closing.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Windows.Forms;
     7 using SharpDisplayInterface;
     8 using System.ServiceModel;
     9 using System.ServiceModel.Channels;
    10 
    11 
    12 namespace SharpDisplayClient
    13 {
    14     /// <summary>
    15     ///
    16     /// </summary>
    17     public partial class ClientInput : IDisplayServiceCallback, IDisposable
    18     {
    19         public void OnConnected()
    20         {
    21             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    22             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    23 
    24             MessageBox.Show("OnConnected()", "Client");
    25         }
    26 
    27 
    28         public void OnServerClosing()
    29         {
    30             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    31             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    32 
    33             //MessageBox.Show("OnServerClosing()", "Client");
    34             Program.iMainForm.CloseConnection();
    35         }
    36 
    37         //From IDisposable
    38         public void Dispose()
    39         {
    40 
    41         }
    42     }
    43 
    44 
    45     /// <summary>
    46     ///
    47     /// </summary>
    48     public partial class ClientOutput : DuplexClientBase<IDisplayService>, IDisplayService
    49     {
    50         public ClientOutput(InstanceContext callbackInstance)
    51             : base(callbackInstance, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
    52         { }
    53 
    54         public void Connect(string aClientName)
    55         {
    56             Channel.Connect(aClientName);
    57         }
    58 
    59         public void SetText(int aLineIndex, string aText)
    60         {
    61             Channel.SetText(aLineIndex, aText);
    62         }
    63 
    64 
    65         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    66         {
    67             Channel.SetTexts(aTexts);
    68         }
    69 
    70 
    71     }
    72 }