mercredi 25 février 2015

Give a reference to another project/winform in SignalR Hub

I am working on SignalR For Winforms official example. The way they handle UI interaction is using the Program instance/reference as you can see in the code below:



public class MyHub : Hub
{
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
public override Task OnConnected()
{
//here they used Program....
Program.MainForm.WriteToConsole("Client connected: " + Context.ConnectionId);
return base.OnConnected();
}
public override Task OnDisconnected(bool graceFull)
{
Program.MainForm.WriteToConsole("Client disconnected: " + Context.ConnectionId);
return base.OnDisconnected(graceFull);
}
}


My question is, I have created an empty solution in Visual Studio and I added 2 projects, one is a WinForms project, The other is a class library.


Obviously I can not give a Program reference from WinForms project in the MyHub class which is in the class library project since as far as I know the Hub or MyHub class should not be instantiated...its just there for the sake of Reflection.


Is there a way that I can pass a reference to my winforms to the MyHub class either statically or something?


Aucun commentaire:

Enregistrer un commentaire