Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created May 22, 2017 21:55
Show Gist options
  • Save JordiCorbilla/92a559012084ae5d113b38dda0a2123e to your computer and use it in GitHub Desktop.
Save JordiCorbilla/92a559012084ae5d113b38dda0a2123e to your computer and use it in GitHub Desktop.
//The MIT License (MIT)
//Copyright (c) 2017 Jordi Corbilla
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
using System;
using System.Windows.Forms;
using Microsoft.AspNet.SignalR.Client;
using System.Globalization;
namespace NotificationSender
{
public partial class Form1 : Form
{
HubConnection hubConnection;
IHubProxy hubProxy;
public Form1()
{
InitializeComponent();
hubConnection = new HubConnection("http://localhost/ClientSite/signalr/hubs/");
hubProxy = hubConnection.CreateHubProxy("NotificationHub");
hubProxy.On<string>("newNotificationReceived", (message) => listBox1.BeginInvoke((MethodInvoker)delegate () { listBox1.Items.Add(string.Format("{0} Message sent: {1}", DateTime.Now.ToString("G", CultureInfo.CurrentCulture), message)); }));
hubConnection.Start().Wait();
}
private void button1_Click(object sender, EventArgs e)
{
hubProxy.Invoke("BroadcastMessageToClients", textBox1.Text, "User1").Wait();
textBox1.Text = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment