468,168 Members | 1,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

calling a delegate in a another thread (compact .NET)

Me again.... second time I type this - the post did not work the first
time...

Similar question as last time, but another problem:
I am running a CE.Net Application and I want to show a small
borderless dialog which shows an animation, that shows, that the
application is still doing something. So far it works until I want to
close the dialog. The dialog has a delegate that I want to invoke,
which will close it. But I run into a System.ArgumentException with
additional Information 'ArgumentException' if I want to invoke the
delegate.

Here is what I am trying to do:
--------------------------------------------------
namespace MyNamespace
{
public delegate void CloseDialogDelegate();

public class MyDialog : System.Windows.Forms.Form
{
public CloseDialogDelegate m_CloseDialog;
public MyDialog()
{
this.m_CloseDialog = new CloseDialogDelegate(CloseDialog);
...
}
...
private void CloseDialog()
{
this.Close();
}
}

public class MainForm : System.Windows.Forms.Form
{
private MyDialog m_MyDialog;
private Thread m_MyDialogThread;
...
private void MyDialogThreadFunc()
{
Application.Run(this.m_MyDialog = new MyDialog());
}
private void OpenMyDialog()
{
this.m_MyDialogThread = new Thread(new
ThreadStart(MyDialogThreadFunc));
this.m_MyDialogThread.Start();
}
private void CloseMyDialog()
{
// here happens the System.ArgumentException
this.m_MyDialog.Invoke(this.m_MyDialog.m_CloseDial og);
}
...
private void DoSomeWork()
{
this.OpenMyDialog();
// Do some work, including excessive
// UI stuff for this form
...
this.CloseMyDialog();
}
}
}
-----------------------------------------------------------

I am confused... I do not even pass arguments to the other thread, the
delegate has no arguments and CF.Net does not support an Invoke with
arguments...

What happens here?
Alexander
Nov 16 '05 #1
3 9583
Alexander <jo*******@gmx.de> wrote:
Me again.... second time I type this - the post did not work the first
time...

Similar question as last time, but another problem:
I am running a CE.Net Application and I want to show a small
borderless dialog which shows an animation, that shows, that the
application is still doing something. So far it works until I want to
close the dialog. The dialog has a delegate that I want to invoke,
which will close it. But I run into a System.ArgumentException with
additional Information 'ArgumentException' if I want to invoke the
delegate.


IIRC, you can only call Control.Invoke with EventHandler delegates in
the Compact Framework.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Jon,

I don't believe this is true. The only thing about calling
Control.Invoke with EventHandler delegates is that it will not honor the
parameters that you pass in. Rather, it will pass the control that Invoke
is called on, and EventArgs.Empty (it does this as an optimization, I
believe).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Alexander <jo*******@gmx.de> wrote:
Me again.... second time I type this - the post did not work the first
time...

Similar question as last time, but another problem:
I am running a CE.Net Application and I want to show a small
borderless dialog which shows an animation, that shows, that the
application is still doing something. So far it works until I want to
close the dialog. The dialog has a delegate that I want to invoke,
which will close it. But I run into a System.ArgumentException with
additional Information 'ArgumentException' if I want to invoke the
delegate.


IIRC, you can only call Control.Invoke with EventHandler delegates in
the Compact Framework.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
I don't believe this is true. The only thing about calling
Control.Invoke with EventHandler delegates is that it will not honor the
parameters that you pass in.


Well, that is indeed true. However, there are other things which make
it special:

1) It's more efficient than using other delegates on the desktop
framework
2) It's all that's supported on the Compact Framework.

And yes, this means that in the Compact Framework, you basically can't
invoke delegates with useful arguments. You have to put the state in
some shared area of data. It sucks :(

See
http://msdn.microsoft.com/mobility/p...netcf/faq/defa
ult.aspx#7.10

If you have a working example of calilng Control.Invoke with something
other than an EventHandler in the Compact Framework, I'd be very
interested.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dean Bortell | last post: by
1 post views Thread by Bill Soudan | last post: by
3 posts views Thread by kplkumar | last post: by
4 posts views Thread by Edwin Gomez | last post: by
15 posts views Thread by =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post: by
9 posts views Thread by Pubs | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.