Re: Work with real-time data
I think best way to do this is making a client/server application where the client subscribes to the server. If any client makes a change, all subscribed clients are notified.
A way to achieve this is using WCF.
Take a look here. This is a simple WCF project where this subscription pattern is used.
Re: Work with real-time data
I agree with danny. If you have an object which can raise events when something happens, all you need to do is trap those events from the client side.
Re: Work with real-time data
Re: Work with real-time data
Quote:
Originally Posted by
arhicoc
.NET Framework 2.0
What do you mean with this? that you are not allowed to use .Net 3.5?
Re: Work with real-time data
Nope. It just means I wonder if there is any solution to achieve this using .NET 2.0.
Re: Work with real-time data
Yes you can achieve the same solution using Remoting. The subscription pattern is the same.
But why not use 3.5?
Re: Work with real-time data
No reason whatsoever. Will give it a try.
Thank you very much.
Re: Work with real-time data
Ok, following a simple example found I've got this:
Client:
Code:
namespace Remote
{
public partial class Client : Form
{
public Client()
{
InitializeComponent();
}
private void Connectbutton_Click(object sender, EventArgs e)
{
TcpChannel chan = new TcpChannel();
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan,true);
RemoteClass oRemoteClass = (RemoteClass)Activator.GetObject(typeof(RemoteClass),"tcp://localhost:8025/Remote.RemoteClass");
DataSet ds = new DataSet();
ds = oRemoteClass.RunSql("SELECT * FROM persoane", "persoane");
dataGridView1.DataSource = ds.Tables["persoane"];
ChannelServices.UnregisterChannel(chan);
}
}
}
RemoteClass:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
namespace Remote
{
class RemoteClass : MarshalByRefObject
{
private string _cs = "Data Source=(local);Initial Catalog=tickets;Integrated Security=True;";
public DataSet RunSql(string cSQL, string cTable)
{
SqlConnection _connection = new SqlConnection(_cs);
SqlCommand _cmd = new SqlCommand(cSQL, _connection);
SqlDataAdapter _adapter = new SqlDataAdapter();
DataSet _dataset = new DataSet();
try
{
_connection.Open();
_adapter.SelectCommand = _cmd;
_adapter.Fill(_dataset, cTable);
}
catch (Exception exception)
{
throw new System.Exception(exception.Message);
}
if (_connection.State != ConnectionState.Closed)
_connection.Close();
return _dataset;
}
}
}
and the Server:
Code:
namespace Remote
{
public partial class ListenerForm : Form
{
TcpChannel channel = new TcpChannel(8025);
public ListenerForm()
{
InitializeComponent();
}
private void Listenbutton_Click(object sender, EventArgs e)
{
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel,true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteClass), "Remote.RemoteClass", WellKnownObjectMode.SingleCall);
EventslistBox.Items.Add("http://localhost/Remote.RemoteClass:8025");
}
}
}
I was just wondering how can I make the updates to show on each client window.
In each client window there is a datagridview.
Also how can the server be informed of the clients connecting, leaving, making changes etc ?
Re: Work with real-time data
Only took a quick look, but I believe this is a realtime Remoting example
http://www.codeproject.com/KB/IP/c_sharp_remoting.aspx
Re: Work with real-time data
1) Remoting is VERY difficult to get "right" when dealing with cross-machine communication.
2) WCF is available as an "Extension" so it CAN be used with VS-2005, although it is MUCH preferred to use VS-2008 and .NET 3.5
Re: Work with real-time data