473,568 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Argument Exception with
additional Information 'ArgumentExcept ion' if I want to invoke the
delegate.

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

public class MyDialog : System.Windows. Forms.Form
{
public CloseDialogDele gate m_CloseDialog;
public MyDialog()
{
this.m_CloseDia log = new CloseDialogDele gate(CloseDialo g);
...
}
...
private void CloseDialog()
{
this.Close();
}
}

public class MainForm : System.Windows. Forms.Form
{
private MyDialog m_MyDialog;
private Thread m_MyDialogThrea d;
...
private void MyDialogThreadF unc()
{
Application.Run (this.m_MyDialo g = new MyDialog());
}
private void OpenMyDialog()
{
this.m_MyDialog Thread = new Thread(new
ThreadStart(MyD ialogThreadFunc ));
this.m_MyDialog Thread.Start();
}
private void CloseMyDialog()
{
// here happens the System.Argument Exception
this.m_MyDialog .Invoke(this.m_ MyDialog.m_Clos eDialog);
}
...
private void DoSomeWork()
{
this.OpenMyDial og();
// Do some work, including excessive
// UI stuff for this form
...
this.CloseMyDia log();
}
}
}
-----------------------------------------------------------

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 10221
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.Argument Exception with
additional Information 'ArgumentExcept ion' 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.co m>
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.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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.Argument Exception with
additional Information 'ArgumentExcept ion' 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.co m>
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.c om> 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.co m>
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
368
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 the method. Throughout the job itself, we use the CallContext class to store information that is needed by many classes in the call stream. This...
15
11746
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 performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to...
4
2354
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 text to a richtextbox named txtMessageBody. 2. Make sure that the scroll is to the bottom of the box. 3. Put the focus back on the box where the user...
1
360
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 which I do not understand because I do not have any arguments. Here is what I am doing: -----------------------------------------------------
1
1452
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 instances (ugh), calling conventions, marshalling, etc. I'm stumped on one issue, though. Quick structural overview: straight C dll wrapped by C#...
3
1893
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 thread to call Send(message) method // everytime someone calls this FooSend method }
4
4788
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 completes it invokes a method from the calling thread. Sort event driven concept with threads. Thanks. Ed Gomez
1
1741
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 Invoke, I declared a delegate to handle the cross-thread call to bring the form forward. Here's my code: Delegate Sub BringMeFront() Public...
15
8179
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 Delegate. My testing showed that actually it was six times faster: 0.5 seconds for 100,000 iterations versus 3.1 seconds. Can anyone explain why? ...
9
3242
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. Example function test (int a, int b);
0
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.