Invoke doesn't return?!

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in the
statement this.Invoke...
how could this be?

thx!!!
 
no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the sender
parameter will contain this control, and the event parameter will contain
EventArgs.Empty. The delegate can also be an instance of MethodInvoker, or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to contains the
3 parameters and the return value and use invoke?!?!?!?

thank you!




Miha Markic said:
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

babylon said:
I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in the
statement this.Invoke...
how could this be?

thx!!!
 
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

babylon said:
no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the sender
parameter will contain this control, and the event parameter will contain
EventArgs.Empty. The delegate can also be an instance of MethodInvoker, or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to contains the
3 parameters and the return value and use invoke?!?!?!?

thank you!




Miha Markic said:
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

babylon said:
I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in the
statement this.Invoke...
how could this be?

thx!!!
 
why msdn said
"any other delegate that takes a void parameter list"?

Miha Markic said:
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

babylon said:
no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the sender
parameter will contain this control, and the event parameter will contain
EventArgs.Empty. The delegate can also be an instance of MethodInvoker, or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to contains the
3 parameters and the return value and use invoke?!?!?!?

thank you!




Miha Markic said:
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in the
statement this.Invoke...
how could this be?

thx!!!
 
Hi Action,
why msdn said
"any other delegate that takes a void parameter list"?

This note is in case that you want to call parameterless methods. It just
advice you that Invoke is optimized for MethodInvoler and EventHandler in
this case. But you can use any delegate. It seems like MSDN is not enough
clear on this point.

--
B\rgds
100 [C# MVP]
Miha Markic said:
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

babylon said:
no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the sender
parameter will contain this control, and the event parameter will contain
EventArgs.Empty. The delegate can also be an instance of
MethodInvoker,
or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to
contains
the
3 parameters and the return value and use invoke?!?!?!?

thank you!




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it
will
call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in the
statement this.Invoke...
how could this be?

thx!!!
 
Then I don't understand why Invoke doesn't return
there is no blocking call in my code...I just try to add a new TreeNode in a
TreeView in the method...
but it blocked

delegate void AddTreeNodeDelegate(string name);
void AddTreeNode(string name)
{
if (this.InvokeRequired == true)
{
this.Invoke(new AddTreeNodeDelegate(AddTreeNode), new object[] {name});
}
else
{
this.treeView.Nodes.Add(new TreeNode(name));
}
}

Stoitcho Goutsev (100) said:
Hi Action,
why msdn said
"any other delegate that takes a void parameter list"?

This note is in case that you want to call parameterless methods. It just
advice you that Invoke is optimized for MethodInvoler and EventHandler in
this case. But you can use any delegate. It seems like MSDN is not enough
clear on this point.

--
B\rgds
100 [C# MVP]
Miha Markic said:
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the sender
parameter will contain this control, and the event parameter will contain
EventArgs.Empty. The delegate can also be an instance of
MethodInvoker,
or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to
another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to contains
the
3 parameters and the return value and use invoke?!?!?!?

thank you!




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will
call
invoke to change some (e.g. add a tree node in treeview) UI elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked
in
the
statement this.Invoke...
how could this be?

thx!!!
 
Troubleshooting:
What happens if you comment this.treeView.Nodes.Add(new TreeNode(name));?
Does it still block?
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

babylon said:
Then I don't understand why Invoke doesn't return
there is no blocking call in my code...I just try to add a new TreeNode in a
TreeView in the method...
but it blocked

delegate void AddTreeNodeDelegate(string name);
void AddTreeNode(string name)
{
if (this.InvokeRequired == true)
{
this.Invoke(new AddTreeNodeDelegate(AddTreeNode), new object[] {name});
}
else
{
this.treeView.Nodes.Add(new TreeNode(name));
}
}

Stoitcho Goutsev (100) said:
Hi Action,
why msdn said
"any other delegate that takes a void parameter list"?

This note is in case that you want to call parameterless methods. It just
advice you that Invoke is optimized for MethodInvoler and EventHandler in
this case. But you can use any delegate. It seems like MSDN is not enough
clear on this point.

--
B\rgds
100 [C# MVP]
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the
sender
parameter will contain this control, and the event parameter will
contain
EventArgs.Empty. The delegate can also be an instance of MethodInvoker,
or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a call to
another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to contains
the
3 parameters and the return value and use invoke?!?!?!?

thank you!




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software
development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it will
call
invoke to change some (e.g. add a tree node in treeview) UI
elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread blocked in
the
statement this.Invoke...
how could this be?

thx!!!
 
It don't block if I remove it....

Miha Markic said:
Troubleshooting:
What happens if you comment this.treeView.Nodes.Add(new TreeNode(name));?
Does it still block?
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

babylon said:
Then I don't understand why Invoke doesn't return
there is no blocking call in my code...I just try to add a new TreeNode
in
a
TreeView in the method...
but it blocked

delegate void AddTreeNodeDelegate(string name);
void AddTreeNode(string name)
{
if (this.InvokeRequired == true)
{
this.Invoke(new AddTreeNodeDelegate(AddTreeNode), new object[] {name});
}
else
{
this.treeView.Nodes.Add(new TreeNode(name));
}
}

Stoitcho Goutsev (100) said:
Hi Action,

why msdn said
"any other delegate that takes a void parameter list"?

This note is in case that you want to call parameterless methods. It just
advice you that Invoke is optimized for MethodInvoler and EventHandler in
this case. But you can use any delegate. It seems like MSDN is not enough
clear on this point.

--
B\rgds
100 [C# MVP]


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to
(e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous
postings.

no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which case the
sender
parameter will contain this control, and the event parameter will
contain
EventArgs.Empty. The delegate can also be an instance of
MethodInvoker,
or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a
call
to
another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any
other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this
requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to
contains
the
3 parameters and the return value and use invoke?!?!?!?

thank you!




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software
development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the network; it
will
call
invoke to change some (e.g. add a tree node in treeview) UI
elements.

the way I call invoke:

void abc()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoke(abc));
}
else
{
// Update UI
}
}

but i found that sometimes the network receiver thread
blocked
in
the
statement this.Invoke...
how could this be?

thx!!!
 
What is the main thread doing?
Is it idle?

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.

babylon said:
It don't block if I remove it....

Miha Markic said:
Troubleshooting:
What happens if you comment this.treeView.Nodes.Add(new TreeNode(name));?
Does it still block?
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

babylon said:
Then I don't understand why Invoke doesn't return
there is no blocking call in my code...I just try to add a new
TreeNode
in
a
TreeView in the method...
but it blocked

delegate void AddTreeNodeDelegate(string name);
void AddTreeNode(string name)
{
if (this.InvokeRequired == true)
{
this.Invoke(new AddTreeNodeDelegate(AddTreeNode), new object[] {name});
}
else
{
this.treeView.Nodes.Add(new TreeNode(name));
}
}

Hi Action,

why msdn said
"any other delegate that takes a void parameter list"?

This note is in case that you want to call parameterless methods.
It
just
advice you that Invoke is optimized for MethodInvoler and
EventHandler
in
this case. But you can use any delegate. It seems like MSDN is not enough
clear on this point.

--
B\rgds
100 [C# MVP]


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi,

No, you can use any delegate you want.
MethodInvoker is just for invoking parameterless methods.

--
Miha Markic [MVP C#] - DXSquad/RightHand .NET consulting & software
development
miha at rthand com www.rthand.com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to
(e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous
postings.

no, of course not

it doesn't work about 2-5%; most of the time it works...

my delegate declared like

public delegate bool doAction(int param1, long param2, bool param3);

I just found that, from MSDN documentation:
"The delegate can be an instance of EventHandler, in which
case
the
sender
parameter will contain this control, and the event parameter will
contain
EventArgs.Empty. The delegate can also be an instance of
MethodInvoker,
or
any other delegate that takes a void parameter list. A call to an
EventHandler or MethodInvoker delegate will be faster than a
call
to
another
type of delegate."

It seems that my delegate doesn't match the 'requirement' -- "any
other
delegate that takes a void parameter list"

my delegate doesn't takes a void parameter list....but this
requirement
seems weird......
If i want a function that takes 3 parameters and return a value.....

Do I really need to use EventHandler and override EventArgs to
contains
the
3 parameters and the return value and use invoke?!?!?!?

thank you!




"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi babylon,

Could it be that abc is blocking?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software
development
miha at rthand com
www.rthand.com

I have 2 threads.
1 is UI thread, the other is a network receiver thread

when my receiver thread receive something from the
network;
 
Back
Top