473,545 Members | 1,890 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 4839
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,...
5
2604
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...
1
2273
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,...
4
3106
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...
4
5794
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...
1
2072
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...
2
10631
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...
4
6625
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
7
2166
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...
0
7478
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...
0
7410
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...
1
7437
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...
1
5343
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...
0
3466
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...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
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
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
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...

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.