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

  • Thread starter Thread starter Alexander
  • Start date Start date
A

Alexander

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_CloseDialog);
}
...
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
 
Alexander said:
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,

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 said:
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/prodtechinfo/devtools/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.
 
Back
Top