Great. Indeed, it passed through the test this weekend. Next step is to put
a similar behavior in the SQL.
My server (winform) calls a method called SendMsgToClient( string message,
int channelID ) to deliver the data string to the connected clients. Can I
do the same call via stored procedure using the OA objects?
I used regasm to generate the typelib and placed my RemoteServer.dll in the
GAC but the message was not sent to the client.
have you done something similar to it? any ideas how to accomplish this?
namespace WRemoteServer
{
public delegate void RegisterEventHandler (object sender, RemoteEventArgs
e);
public class RemoteServer : MarshalByRefObject
{
public static event RegisterEventHandler InvokeHostForm;
public event RegisterEventHandler InvokeCallbackMethod,
InvokeCallbackMethod2;
public void RemoteServerMethod(string str, out string strOut)
{
RemoteEventArgs e = new RemoteEventArgs(str);
if(InvokeHostForm != null)
InvokeHostForm(this, e);
strOut = str + " Returned from Server!";
}
public void SendMsgToClient(string str, int msg)
{
RemoteEventArgs e = new RemoteEventArgs(str);
// Fire Client Event
if (InvokeCallbackMethod != null && (msg == 1 || msg==0))
InvokeCallbackMethod(this, e);
else if (InvokeCallbackMethod2 != null && (msg == 2 || msg==0))
InvokeCallbackMethod2(this, e);
}
// This is to insure that when created as a Singleton, the first instance
never dies,
// regardless of the time between users messages.
public override object InitializeLifetimeService()
{
return null;
}
}
public abstract class RemotelyDelegatableObject : MarshalByRefObject
{
public void SubmissionCallback (object sender, RemoteEventArgs submitArgs)
{
try
{
InternalSubmissionCallback (sender, submitArgs) ;
}
catch{}
}
protected abstract void InternalSubmissionCallback (object sender,
RemoteEventArgs submitArgs) ;
}
[Serializable]
public class RemoteEventArgs : EventArgs
{
public string SendMessage;
public string usrName, srvType;
public RemoteEventArgs(string msg)
{
this.SendMessage = msg;
}
public RemoteEventArgs(string msg, string name, string type)
{
this.SendMessage = msg;
this.usrName = name;
this.srvType = type;
}
}
}
[quoted text, click to view] "Mehdi" <vioccc@REMOVEME.gmail.com> wrote in message
news:wnjeiauybgdw$.yjpg8eacbljr$.dlg@40tude.net...
> On Sat, 13 Aug 2005 06:55:09 +0800, edge wrote:
>
>> Great hints!
>> Well, seems that it is working, but instead of calling the new
>> MethodInvoker
>> I am using a delegate. Please look at how i am doing:
>
> MethodInvoker is actually just a normal delegate provided for your
> convenience in the .NET framework.
>
>> a few more questions:
>> Is this the way it should be? is it a valid alternative?
>
> Yes, it looks alright to me. Something that i like to do, but this is
> purely for aestetical reasons, is to put the marshalling code and the
> actual UI code in a single method. In your code, you've got the
> AddRowToDataGrid method that modifies your datagrid and the UpdateMyClient
> method that just marshall the call to AddRowToDataGrid to the UI thread.
> You could rewrite it with a single method like that:
>
> public void UpdateMyClient( string data )
> {
> if (this.InvokeRequired)
> {
> // We are in a workder thread,
> // let's marshall ourself to the UI thread
> this.Invoke( new SetIncomingDataTextDelegate( UpdateMyClient ), new
> object[] { data } );
> }
> else
> {
> // We are now in the UI thread, let's update
> // this datagrid
> // Put the code that was in AddRowToDataGrid here
> }
> }
>
>