473,396 Members | 1,608 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,396 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 4826
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
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...
0
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...
0
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...
0
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,...

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.