Click here to Skip to main content
15,907,910 members
Home / Discussions / C#
   

C#

 
GeneralRe: Speedup app startup time Pin
paulb10-Apr-02 19:23
paulb10-Apr-02 19:23 
GeneralRe: Speedup app startup time Pin
Nick Parker11-Apr-02 5:47
protectorNick Parker11-Apr-02 5:47 
GeneralRe: Speedup app startup time Pin
Kannan Kalyanaraman16-Apr-02 0:42
Kannan Kalyanaraman16-Apr-02 0:42 
GeneralRe: Speedup app startup time Pin
Kannan Kalyanaraman16-Apr-02 0:47
Kannan Kalyanaraman16-Apr-02 0:47 
GeneralRe: Speedup app startup time Pin
James T. Johnson16-Apr-02 6:56
James T. Johnson16-Apr-02 6:56 
GeneralRe: Speedup app startup time Pin
Kannan Kalyanaraman16-Apr-02 8:19
Kannan Kalyanaraman16-Apr-02 8:19 
GeneralRe: Speedup app startup time Pin
James T. Johnson16-Apr-02 11:45
James T. Johnson16-Apr-02 11:45 
GeneralGet remote object and respond to an event Pin
wzrd10-Apr-02 9:27
wzrd10-Apr-02 9:27 
I'm currently trying to get a remote object, using Remoting... I can get the object, but I can't grab a event the object fires. This is all example code and I just can't seem to get it work. I get the object, but the remote object doesn't see the client sign up to watch for the event, so it never fires the event. Or if you have a better way for my Server and Client to communicate, don't hesitate to share.

Any help with would greatly appreciated. If you have more questions, please email me.

[Server]
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Server
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "Hi", WellKnownObjectMode.SingleCall);

Console.WriteLine("Hit to exit");
Console.ReadLine();
}
}
}

[Client]
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Client
{
[STAThread]
static void Main(string[] args)
{
//RemotingConfiguration.Configure("Client.exe.config");

ChannelServices.RegisterChannel(new TcpClientChannel());
RemoteObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8086/Hi");

EventSink sink = new EventSink();

// register client sink in server - subscribe to event
obj.Status += new StatusEvent(sink.StatusHandler);

obj.LongWorking(5000);


// unsubscribe to event
obj.Status -= new StatusEvent(sink.StatusHandler);

obj.LongWorking(5000);

Console.WriteLine("Hit to exit");
Console.ReadLine();
}
}
}


[RemoteObject]
using System;

namespace Test.Remote
{
[Serializable]
public class StatusEventArgs
{
public StatusEventArgs(string m)
{
message = m;
}

public string Message
{
get
{
return message;
}
set
{
message = value;
}
}

private string message;
}


public delegate void StatusEvent(object sender, StatusEventArgs e);

/// <summary>
/// Summary description for Class1.
/// </summary>
public class RemoteObject : MarshalByRefObject
{
public RemoteObject()
{
Console.WriteLine("RemoteObject constructor called");
}

public event StatusEvent Status;

public void LongWorking(int ms)
{
Console.WriteLine("RemoteObject: LongWorking() Started");

StatusEventArgs e = new StatusEventArgs(
"Message for Client: LongWorking() Started");
// fire event
if (Status != null)
{
Console.WriteLine("RemoteObject: Firing Starting Event");
Status(this, e);
}

System.Threading.Thread.Sleep(ms);

e.Message = "Message for Client: LongWorking() Ending";
// fire ending event
if (Status != null)
{
Console.WriteLine("RemoteObject: Firing Ending Event");
Status(this, e);
}

Console.WriteLine("RemoteObject: LongWorking() Ending");
}
}
}

[EventSink]
using System;
using System.Runtime.Remoting.Messaging;

namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class EventSink : MarshalByRefObject
{
public EventSink()
{
Console.WriteLine("EventSink: Constructor called");
}

[OneWay]
public void StatusHandler(object sender, StatusEventArgs e)
{
Console.WriteLine("EventSink: Event occurred: " + e.Message);
}
}
}

-wzrd
wizardque@yahoo.com
GeneralHosting .NET controls in IE ***LOCALLY*** Pin
10-Apr-02 8:29
suss10-Apr-02 8:29 
GeneralConverting C structures to C# equivalents... Pin
10-Apr-02 1:29
suss10-Apr-02 1:29 
GeneralRe: Converting C structures to C# equivalents... Pin
James T. Johnson10-Apr-02 10:28
James T. Johnson10-Apr-02 10:28 
GeneralVisual C# .NET Standard edition - missing features Pin
Mario123459-Apr-02 22:44
Mario123459-Apr-02 22:44 
GeneralRe: Visual C# .NET Standard edition - missing features Pin
ez210-Apr-02 7:19
ez210-Apr-02 7:19 
QuestionAre there any APIs in c# that i can use to parse a email message? Pin
Gentri Wind9-Apr-02 18:38
Gentri Wind9-Apr-02 18:38 
AnswerRe: Are there any APIs in c# that i can use to parse a email message? Pin
James T. Johnson9-Apr-02 19:25
James T. Johnson9-Apr-02 19:25 
GeneralRe: Are there any APIs in c# that i can use to parse a email message? Pin
Paul Watson21-Jun-02 7:05
sitebuilderPaul Watson21-Jun-02 7:05 
QuestionWhy so many class in framework sealed? Pin
9-Apr-02 17:49
suss9-Apr-02 17:49 
AnswerRe: Why so many class in framework sealed? Pin
Gerald Schwab9-Apr-02 17:54
Gerald Schwab9-Apr-02 17:54 
GeneralRe: Why so many class in framework sealed? Pin
9-Apr-02 20:01
suss9-Apr-02 20:01 
AnswerRe: Why so many class in framework sealed? Pin
James T. Johnson9-Apr-02 19:10
James T. Johnson9-Apr-02 19:10 
AnswerRe: Why so many class in framework sealed? Pin
Andy Smith9-Apr-02 20:10
Andy Smith9-Apr-02 20:10 
GeneralRe: Why so many class in framework sealed? Pin
Nick Parker10-Apr-02 6:42
protectorNick Parker10-Apr-02 6:42 
GeneralBitmap Button Pin
9-Apr-02 9:31
suss9-Apr-02 9:31 
GeneralRe: Bitmap Button Pin
James T. Johnson9-Apr-02 13:50
James T. Johnson9-Apr-02 13:50 
Generalswitch enhancement in C# Pin
ovarlamov9-Apr-02 8:27
ovarlamov9-Apr-02 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.