473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Remoting - Updating Textbox from server messages

Hello,

I'm writing a server client application and I'm having a terrible time
getting one section to work. This is my first time using .net remoting, so
please bear with me if I'm doing something incorrectly. To give a brief
layout of my program, the server side hosts a series of functions for running
tests, this server application will run on four separate boxes. My client
application has access to all four of the server applications, and sends jobs
to those server to complete. On my client form, there are text boxes,
representing status on the jobs from each of the four servers.

My problem is getting those text boxes to update from the form, I'm using a
remote object that the client creates. I have this object referenced in the
server and it has one function.. SendMessage(string message)... When the
client recieves that message, I need it to update the text box in my Form
class. I've tried several different ways, but I keep running into Cross
Threading errors, or my program completely locks up. I've tried using
Events, but those still didn't seem to work.

Does anyone have any advice? I just purchased a book that will hopefully
help (Advanced Remoting (using C#)), I'm looking forward to recieving it and
hopefully it's full of great advice. In the meantime, I have a job to do and
I'm stuck.

Thanks for any help!

Cory B.
May 12 '06 #1
13 6156
I supose the problem is in cross-threading operation.
This means that you cannot modify control in other thread that that
created control.
you can use delegates as workaround

Hope this helps

Galin Iliev[MCSD.NET]
www.galcho.com

May 12 '06 #2
Could you give an example of this? I played around with the delegates, but I
wasn't sure exactly how it worked. Would the delgate be placed in the remote
object or the class that contains the text box?

"Galcho[MCSD.NET]" wrote:
I supose the problem is in cross-threading operation.
This means that you cannot modify control in other thread that that
created control.
you can use delegates as workaround

Hope this helps

Galin Iliev[MCSD.NET]
www.galcho.com

May 12 '06 #3
see here
there is example in folder %installation folder%\Data
Access\Asynchronous Queries

http://www.microsoft.com/downloads/d...displaylang=en
this is code from there
//declare delegate
private delegate void DisplayInfoDelegate(string Text);
/// <summary>
/// This method displays the user message text that occurs during
processing
/// and after processing completes
/// </summary>
/// <param name="Text"></param>
private void DisplayResults(string Text)
{
this.messageReturned.Text = Text;

}

//call like this in method
DisplayInfoDelegate myUserDelegate = new
DisplayInfoDelegate(DisplayResults);
myUserDelegate(userMessage);
hope this helps

Galin Iliev[MCSD.NET]
www.galcho.com

May 12 '06 #4
Thanks for the reply, I downloaded those code samples, but I was unable to
find this specific example that you've given. I understand what your doing
there, but how am I able to access that delegate from a different class?
That's where I'm getting confused. Here is an example of what I'm doing.

//Remote Client Object

public class CallBackObject : MarshalByRefObject
{

public void ClientReciever(string msg, int Source)
{
//this needs to call Form1 and update the text box
Form1.UpdateText(msg); //I know this won't work, just for
reference...
}
}

public class Form1 : Form
{
public void UpdateTest(string message)
{
tbTest.AppendText(message + "\r\n");
}
}

I'm not quite sure where the delegates would go and how to call them from
one class to another. Could you point me in the right direction?

Thanks,

Cory B.
"Galcho[MCSD.NET]" wrote:
see here
there is example in folder %installation folder%\Data
Access\Asynchronous Queries

http://www.microsoft.com/downloads/d...displaylang=en
this is code from there
//declare delegate
private delegate void DisplayInfoDelegate(string Text);
/// <summary>
/// This method displays the user message text that occurs during
processing
/// and after processing completes
/// </summary>
/// <param name="Text"></param>
private void DisplayResults(string Text)
{
this.messageReturned.Text = Text;

}

//call like this in method
DisplayInfoDelegate myUserDelegate = new
DisplayInfoDelegate(DisplayResults);
myUserDelegate(userMessage);
hope this helps

Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #5
Hi Brosto,
this is code that should work according me:

public class CallBackObject : MarshalByRefObject
{
//probably keep reference to opened form
Form1 frm;

//declare delegate
private delegate void DisplayInfoDelegate(string Text);

public void ClientReciever(string msg, int Source)
{
DisplayInfoDelegate displayInfo = new
DisplayInfoDelegate(frm.UpdateTest);
displayInfo(msg);
}
}

public class Form1 : Form
{
public void UpdateTest(string message)
{
tbTest.AppendText(message + "\r\n");
}
}
if you have any problems just post here and we will try to resolve
them.

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #6
Hi Galcho,

Thank you for all your help on this, I really do appreciate it.

When I use the code you just gave me, I recieve the following error:

System.ArgumentException was unhandled by user code
Message="Delegate to an instance method cannot have null 'this'."
Source="mscorlib"
StackTrace:
at System.MulticastDelegate.ThrowNullThisInDelegateTo Instance()
at System.MulticastDelegate.CtorClosed(Object target, IntPtr methodPtr)
at RegressionControlPanel.CallBackObject.ClientReciev er(String msg,
Int32 Source) in D:\Visual Studio
2005\Projects\RegressionControlPanel\RegressionCon trolPanel\RemoteObject.cs:line 22
at
System.Runtime.Remoting.Messaging.StackBuilderSink ._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext,
Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink .PrivateProcessMessage(RuntimeMethodHandle
md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext,
Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink .SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
If I create a new instance of form1, then the update does not show on the
form I'm trying to update. Is there a way I can get "frm" to reference to my
active form?

Thanks!

Cory B.
"Galcho[MCSD.NET]" wrote:
Hi Brosto,
this is code that should work according me:

public class CallBackObject : MarshalByRefObject
{
//probably keep reference to opened form
Form1 frm;

//declare delegate
private delegate void DisplayInfoDelegate(string Text);

public void ClientReciever(string msg, int Source)
{
DisplayInfoDelegate displayInfo = new
DisplayInfoDelegate(frm.UpdateTest);
displayInfo(msg);
}
}

public class Form1 : Form
{
public void UpdateTest(string message)
{
tbTest.AppendText(message + "\r\n");
}
}
if you have any problems just post here and we will try to resolve
them.

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #7
I think the problem with this could be resolved as passing frm
reference as parameter - just as msg,
other solutions is go get it from outside - for instance some other
class could keep reference for you and when you receive callback from
server you ask other class for active form and perform update on it

I think second solution is much better.

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 16 '06 #8
Hi Galin,

I used the starting class that creates the form instanace and made a public
static instance of Form1 (see code below..) However, I'm back to square one
with the same error message I was recieving before:

Cross-thread operation not valid: Control 'tbTest' accessed from a thread
other than the thread it was created on.

I can't pass the form as a reference in the parmeter because the server
would not have a reference to that object. This could be some easy solution
and I'm just not seeing it. Unfortunetly where I work, no one else really
knows C# so I don't have a goto person for advice. Let me know if you have
anymore idea's on how to get around this. Thanks for all the help!

Cory B.

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static ServerTalk ST = new ServerTalk();
public static Form1 _Form1;

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
_Form1 = new Form1();
Application.Run(_Form1);
}

}

partial class Form1 : Form
{
private void UpdateTestBox()
{
tbTest.AppendText(TestMessage + "\r\n");
}
}

public class CallBackObject : MarshalByRefObject
{
//declare delegate
private delegate void DisplayInfoDelegate(string Text);

public void ClientReciever(string msg, int Source)
{
DisplayInfoDelegate displayInfo = new
DisplayInfoDelegate(Program._Form1.UpdateTest);
displayInfo(msg);
}
}


May 16 '06 #9
take a look here
http://www.codeproject.com/csharp/remotingcallbacks.asp

if this doesn't help you could you send me small test project and I can
fix things for (do not send whole project of course) at
galcho@_NOSPAM_gmail.com

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 17 '06 #10
Hi Galin,

Thanks for the reply... I have looked at the sample you posted, but I was
unable to get anyhwhere with it. They're doing something a little different
than what I'm doing. What I'm trying to do seems so simple, but it's been a
real pain so far. Anyhow, I've made a sample project with a client, server
and the remote objects. If you run them, you should get the same cross
threading errors that i was recieving. Let me know what you think.

Thanks,

Cory B.
May 17 '06 #11
I do not see the project.
there is nothing in my mail too.

Send it to me and I will check

Regards
Galin Iliev[MCSD.NET]

May 17 '06 #12
Please check again, I had the address wrong the first time.

Thanks,

Cory B.

"Galcho[MCSD.NET]" wrote:
I do not see the project.
there is nothing in my mail too.

Send it to me and I will check

Regards
Galin Iliev[MCSD.NET]

May 17 '06 #13
I believe I may have figured it out.

On my callback method, I used the Form.BeginInvoke method:

Object args = msg;
DisplayInfoDelegate displayInfo = new
DisplayInfoDelegate(Program.x.UpdateTest);
Program.x.BeginInvoke(displayInfo, args);

This seems to work and doesn't lock up the UI at all. Thanks for all your
help!

-Cory B.

May 18 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dennis Owens | last post by:
Read below for previous conversation. We are developing an application that will some day run on anything from a computer down to a PDA (this is were the Lightweight comes in). The messaging...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
3
by: S.Creek | last post by:
Hi, I am trying to build a multi clients application with C# that will send and receive messages using a listener on a server, the computers are all on the same LAN, the listener need to...
22
by: Tim | last post by:
Hi A while ago I got some help in writing a mock console. The idea was to write a VB app that contained a textbox, then run a process from within the app and redirect the stdout to the textbox. ...
2
by: greg.merideth | last post by:
I have a project where we have a windows service that creates a remoting object for an external client application to communicate with using ipc. We've discovered the client is making updates to...
1
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a...
7
by: Diego F. | last post by:
Hello. I have a windows service running that listens to a port and makes insert queries in a database. I need to make an interface, so my idea is creating a simple windows application that just...
3
by: Trez | last post by:
Hey guys, Am new at using ASP.Net. am having some problems updating my SQL DB. whenever i try i get this Error. Can someone help me? Incorrect syntax near 'nvarchar'. Description: An unhandled...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.