473,790 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(str ing 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 6187
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\Asynchro nous Queries

http://www.microsoft.com/downloads/d...displaylang=en
this is code from there
//declare delegate
private delegate void DisplayInfoDele gate(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.messageRet urned.Text = Text;

}

//call like this in method
DisplayInfoDele gate myUserDelegate = new
DisplayInfoDele gate(DisplayRes ults);
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 : MarshalByRefObj ect
{

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

public class Form1 : Form
{
public void UpdateTest(stri ng message)
{
tbTest.AppendTe xt(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\Asynchro nous Queries

http://www.microsoft.com/downloads/d...displaylang=en
this is code from there
//declare delegate
private delegate void DisplayInfoDele gate(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.messageRet urned.Text = Text;

}

//call like this in method
DisplayInfoDele gate myUserDelegate = new
DisplayInfoDele gate(DisplayRes ults);
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 : MarshalByRefObj ect
{
//probably keep reference to opened form
Form1 frm;

//declare delegate
private delegate void DisplayInfoDele gate(string Text);

public void ClientReciever( string msg, int Source)
{
DisplayInfoDele gate displayInfo = new
DisplayInfoDele gate(frm.Update Test);
displayInfo(msg );
}
}

public class Form1 : Form
{
public void UpdateTest(stri ng message)
{
tbTest.AppendTe xt(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.Argument Exception was unhandled by user code
Message="Delega te to an instance method cannot have null 'this'."
Source="mscorli b"
StackTrace:
at System.Multicas tDelegate.Throw NullThisInDeleg ateToInstance()
at System.Multicas tDelegate.CtorC losed(Object target, IntPtr methodPtr)
at RegressionContr olPanel.CallBac kObject.ClientR eciever(String msg,
Int32 Source) in D:\Visual Studio
2005\Projects\R egressionContro lPanel\Regressi onControlPanel\ RemoteObject.cs :line 22
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink._PrivateP rocessMessage(I ntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInConte xt,
Object[]& outArgs)
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink.PrivatePr ocessMessage(Ru ntimeMethodHand le
md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInConte xt,
Object[]& outArgs)
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink.SyncProce ssMessage(IMess age msg, Int32 methodPtr, Boolean fExecuteInConte xt)
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 : MarshalByRefObj ect
{
//probably keep reference to opened form
Form1 frm;

//declare delegate
private delegate void DisplayInfoDele gate(string Text);

public void ClientReciever( string msg, int Source)
{
DisplayInfoDele gate displayInfo = new
DisplayInfoDele gate(frm.Update Test);
displayInfo(msg );
}
}

public class Form1 : Form
{
public void UpdateTest(stri ng message)
{
tbTest.AppendTe xt(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.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
_Form1 = new Form1();
Application.Run (_Form1);
}

}

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

public class CallBackObject : MarshalByRefObj ect
{
//declare delegate
private delegate void DisplayInfoDele gate(string Text);

public void ClientReciever( string msg, int Source)
{
DisplayInfoDele gate displayInfo = new
DisplayInfoDele gate(Program._F orm1.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

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

Similar topics

0
1551
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 that we want to send will be very straightforward. If one of the clients has changed some data, the other clients need to know about it. If the clients are not on line then the message may have to wait until they are on line. The messages
4
3118
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 it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
11
11961
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 streams. I ran the test for 50K, 100K, 500K iterations, where each iteration consists of sending an object from a client process to a server process, and the server process sends back an ack. Here are the results: .NET Remoting C++...
3
2087
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 identify a message in the MS Queues he listens on, and send it to the relevant clients (not all need to get all messages) it can send the message through an event or an interface.?
22
3154
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. My problem was that textboxes have maximum length limits, so I had to write a function to erase some of the text when it started getting full. That appears to work, but I am experiencing odd behaviour when the textbox text gets long. When it got to...
2
3981
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 the class fields by calling the update methods in the remoting object class and while thats not an issue I'm curious about threading with remote calls. I can't find much in the way of what threading issues can occur. If the service's thread...
1
2090
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 UI for interacting with the instruments. Readings from the instruments are periodically sent to the clients, and clients will send commands to the server based on user input. In normal usage there will be around 6 clients connected, with a...
7
2282
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 shows messages from the service. Can I do that with remoting? What are the main steps to do that? --
3
1883
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 exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.