Client/MainForm.cs
author sl
Thu, 14 Aug 2014 09:57:44 +0200
changeset 26 a6fb2b2f73b0
parent 25 6f10207a89a8
child 29 c4e03315035c
permissions -rw-r--r--
Adding disconnect function to our interface.
sl@18
     1
using System;
sl@18
     2
using System.Collections.Generic;
sl@18
     3
using System.ComponentModel;
sl@18
     4
using System.Data;
sl@18
     5
using System.Drawing;
sl@18
     6
using System.Linq;
sl@18
     7
using System.Text;
sl@18
     8
using System.Threading.Tasks;
sl@18
     9
using System.Windows.Forms;
sl@18
    10
using System.ServiceModel;
sl@18
    11
using System.ServiceModel.Channels;
sl@20
    12
sl@18
    13
sl@18
    14
namespace SharpDisplayClient
sl@18
    15
{
sl@18
    16
    public partial class MainForm : Form
sl@18
    17
    {
sl@26
    18
        Client iClient;
sl@26
    19
        Callback iCallback;
sl@18
    20
sl@18
    21
        public MainForm()
sl@18
    22
        {
sl@18
    23
            InitializeComponent();
sl@18
    24
        }
sl@18
    25
sl@18
    26
        private void buttonSetText_Click(object sender, EventArgs e)
sl@18
    27
        {
sl@19
    28
            //iClient.SetText(0,"Top");
sl@19
    29
            //iClient.SetText(1, "Bottom");
sl@26
    30
            iClient.SetTexts(new string[] { "Top", "Bottom" });
sl@18
    31
        }
sl@18
    32
sl@18
    33
        private void MainForm_Load(object sender, EventArgs e)
sl@18
    34
        {
sl@26
    35
            iCallback = new Callback();
sl@25
    36
            //Instance context is then managed by our client class
sl@26
    37
            InstanceContext instanceContext = new InstanceContext(iCallback);
sl@26
    38
            iClient = new Client(instanceContext);
sl@18
    39
sl@26
    40
            iClient.Connect("TestClient");
sl@18
    41
sl@18
    42
        }
sl@21
    43
sl@21
    44
        public void CloseConnection()
sl@21
    45
        {
sl@26
    46
            iClient.Close();
sl@26
    47
            iClient = null;
sl@26
    48
            iCallback = null;
sl@26
    49
        }
sl@26
    50
sl@26
    51
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
sl@26
    52
        {
sl@26
    53
            if (iClient != null) //Could catch exception instead
sl@26
    54
            {
sl@26
    55
                iClient.Disconnect();
sl@26
    56
                CloseConnection();
sl@26
    57
            }
sl@21
    58
        }
sl@18
    59
    }
sl@18
    60
}