473,588 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remoting and using the Invoke method to modify a form object

hi all,

I'm having a few problems whereby my application is hanging when using the
Invoke method of a form's control.

Basically, when a user clicks a button on the form, it calls a remote
function, which in turn fires an event that is caught by the form.
The form then need to add a value passed in the event to a form object,
however, when using the Invoke method, it just hangs.

Here's a snippet of the code;

public void NotifyUserAdded (string username)
{
TreeNodeCollect ion treeNodeCollect ion = treeMachines.No des[0].Nodes;
TreeNode treeNodeParent = treeMachines.No des[0];

AddDelegate addDelegate = new AddDelegate(tre eNodeCollection .Add);
ExpandDelegate expandNodeDeleg ate = new
ExpandDelegate( treeNodeParent. Expand);

treeMachines.In voke(addDelegat e, new object[] {new
TreeNode(userna me,0,0)});
treeMachines.In voke(expandNode Delegate);

}

the two delegates are obviously previously defined.
delegate int AddDelegate(Tre eNode treeNode);
delegate void ExpandDelegate( );

Sometimes it works, but it's very slow. If i take the invoke out and use
the Node.Add method, it works... but obviously not correctly - as 50% of the
time it throws the "must use invoke" exception.

Any ideas?

TIA

Sam Martin

Nov 15 '05 #1
1 4847
Hi,

If I read this correctly the NotifyUserAdded is the event that is
triggered by the remote call. This means the event will be called on a
thread which is not the UI thread (the thread on which the control/component
was constructed). Any calls to UI objects may hang if they are made in a
thread which is not the UI thread. It may also be that because you have
used Invoke which blocks and not BeginInvoke which does not.

I would suggest a slightly different model:

public delegate void NotifyUserAdded EventHandler( string username );
public void NotifyUserAdded ( string username )
{
if( this.InvokeRequ ired == true )
{
// From memory so this may be wrong syntax!.
this.BeginInvok e( new NotifyUserAdded EventHandler(
this.NotifyUser Added ), new object[] { username } );
}
else
{
// Do your UI stuff here without any need to invoke - just as
normal.
}
}

Of course this is just one way of doing things. Hopefully this will solve
your hanging issue.

Regards,

- Bruce.


"boxim" <sa*********@ya hoo.co.uk> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
hi all,

I'm having a few problems whereby my application is hanging when using the
Invoke method of a form's control.

Basically, when a user clicks a button on the form, it calls a remote
function, which in turn fires an event that is caught by the form.
The form then need to add a value passed in the event to a form object,
however, when using the Invoke method, it just hangs.

Here's a snippet of the code;

public void NotifyUserAdded (string username)
{
TreeNodeCollect ion treeNodeCollect ion = treeMachines.No des[0].Nodes;
TreeNode treeNodeParent = treeMachines.No des[0];

AddDelegate addDelegate = new AddDelegate(tre eNodeCollection .Add);
ExpandDelegate expandNodeDeleg ate = new
ExpandDelegate( treeNodeParent. Expand);

treeMachines.In voke(addDelegat e, new object[] {new
TreeNode(userna me,0,0)});
treeMachines.In voke(expandNode Delegate);

}

the two delegates are obviously previously defined.
delegate int AddDelegate(Tre eNode treeNode);
delegate void ExpandDelegate( );

Sometimes it works, but it's very slow. If i take the invoke out and use
the Node.Add method, it works... but obviously not correctly - as 50% of the time it throws the "must use invoke" exception.

Any ideas?

TIA

Sam Martin

Nov 15 '05 #2

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

Similar topics

0
376
by: boxim | last post by:
hi all, I'm having a few problems whereby my application is hanging when using the Invoke method of a form's control. Basically, when a user clicks a button on the form, it calls a remote function, which in turn fires an event that is caught by the form. The form then need to add a value passed in the event to a form object, however, when using the Invoke method, it just hangs.
5
2609
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or sequence of methods) which will do the actual work (prepare a binary file) and return it to the client. It seems (after all the reading) that in order to prevent passing the auth info every method call, I have to implement Client activated object,...
1
2278
by: Bruce M. Carroll | last post by:
I am doing some work a distributed application, which uses events and remoting to accomplish the signaling between applications. This all works. The problem I have (I think) is that since remoting/events essentially guarantees that you are working in a multi-threaded environment, the developer of the application that consumes these events, if they intend on using these events to update a UI, has to understand delegates and invokes....
4
3110
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()
4
5798
by: GTi | last post by:
I have a program that will act as an Remoting server AND client. This program can be loaded on one macine or it can be loaded on several machines. But it will only be one master program available, all the other is "clients" handling tasks. The master program will dellegate tasks. When the program starts it will ask if there is any "master" available on the network (a BROADCAST to all machines). If there is no master responds it will...
1
2075
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...
2
10637
by: Sagaert Johan | last post by:
Hi When the remoting server starts and the client immediate begins calling the remote object on the server no problems. But when the client does not need to access the remote object for some time the connection seems to be broken on the next attempt to do a call to the remote object on the server. (i need to restart the server application to get it working again ). So it appears if the remoting connection is idle for some time (...
4
6631
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
7
2170
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am trying to see if I can call a Library remotely. The library contains a Form that I want to display then pass back some data to user that called this form remotely. I have it working some-what. I am able to call form remotely and return data to client but somewhere after closing remote form and returning data - I get a Windows exception -
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7862
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
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
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
5398
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
3847
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...
1
2372
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
1
1459
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.