473,386 Members | 1,610 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,386 software developers and data experts.

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)
{
TreeNodeCollection treeNodeCollection = treeMachines.Nodes[0].Nodes;
TreeNode treeNodeParent = treeMachines.Nodes[0];

AddDelegate addDelegate = new AddDelegate(treeNodeCollection.Add);
ExpandDelegate expandNodeDelegate = new
ExpandDelegate(treeNodeParent.Expand);

treeMachines.Invoke(addDelegate, new object[] {new
TreeNode(username,0,0)});
treeMachines.Invoke(expandNodeDelegate);

}

the two delegates are obviously previously defined.
delegate int AddDelegate(TreeNode 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 4825
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 NotifyUserAddedEventHandler( string username );
public void NotifyUserAdded( string username )
{
if( this.InvokeRequired == true )
{
// From memory so this may be wrong syntax!.
this.BeginInvoke( new NotifyUserAddedEventHandler(
this.NotifyUserAdded ), 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*********@yahoo.co.uk> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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)
{
TreeNodeCollection treeNodeCollection = treeMachines.Nodes[0].Nodes;
TreeNode treeNodeParent = treeMachines.Nodes[0];

AddDelegate addDelegate = new AddDelegate(treeNodeCollection.Add);
ExpandDelegate expandNodeDelegate = new
ExpandDelegate(treeNodeParent.Expand);

treeMachines.Invoke(addDelegate, new object[] {new
TreeNode(username,0,0)});
treeMachines.Invoke(expandNodeDelegate);

}

the two delegates are obviously previously defined.
delegate int AddDelegate(TreeNode 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
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...
5
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...
1
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...
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...
4
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...
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...
2
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...
4
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
7
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.