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

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 10192
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Marina | last post by:
Hi, we have an app, that executes jobs submitted from an outside application. It executes them asynchronusly, by creating a delegate to the method that can run the job, and calling BeginInvoke on...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
4
by: Dean Bortell | last post by:
I am writing a multi-threaded program with a worker thread. I want the rich text box to auto scroll down as the text is added. Here is what I want to happen: From the worker thread: 1. Add the...
1
by: Alexander | last post by:
Me again... ;) I am running a small borderless dialog in a seperate thread, that shows a small animation and I want to signal it to close itself. But I am running in a System.ArgumentException...
1
by: Bill Soudan | last post by:
Hi all, I'm a MS/.NET newbie, diving right into CLR interop. I've worked through the various issues foreign to me as a UNIX guy: multiple heap issues because I was linking to different CRT...
3
by: kplkumar | last post by:
I want to call a method passing a parameter. I want to do this call on a seperate thread. For example, public class Foo { public static void FooSend(Message message) { // Start a seperate...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
1
by: SAL | last post by:
Hello, I'm developing this remoting app (.net 2.0) and I need to bring the server app's form to the front often. Since you can not do cross-thread communication on a form or control without using...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.