Re: Problem with multithreaded C# app on Windows CE

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



For .NET CF 2.0, BeginInvoke is supported. I use it in an app target
for devices running .NET CF 2.0. SP1. However, my word is often
questioned and more often questionable, so the following is straight
from MS:
---------------------------------------------
(http://msdn.microsoft.com/netframework/programming/netcf/default.aspx?pull=/library/en-us/dnnetcomp/html/whats_new_netcf2.asp_:
Threads and the User Interface

The .NET Compact Framework 2.0 now supports asynchronous execution of a
delegate on a user interface thread. Unlike the .NET Compact Framework
1.0 that supports only the Control.Invoke method (which synchronously
executes a delegate on a control's owning thread), the .NET Compact
Framework 2.0 provides Control.BeginInvoke that asynchronously executes
a delegate on the control's owning thread. The Control.EndInvoke method
is also provided. When called, the EndInvoke method returns the results
of an asynchronous operation.
---------------------------------------------

I'd check which version of the CF is installed by running
\Windows\cgacutil.exe. Re-install .NET CF if CF 2.0 is on the device.

Good Luck


Paul G. Tobey [eMVP] wrote:
Yes, that's what I'm saying. It's in the class signature (the method exists,
in some sense), but any method that calls BeginInvoke() will generate a
not-supported exception when that method is invoked. Delegates are
supported and I don't see any problems with them, but BeginInvoke isn't.
You can easily, or at least relatively easily, change the code to use
Control.Invoke to call back into the UI thread. You can't pass a random set
of parameters, but you can pass an EventArgs subclass which holds your extra
parameters as fields, instead. It's not as clean as the desktop, but it
works. Something like this:

-----

// Must use Invoke, not BeginInvoke, in .NET CF.

InvokeEventArgs args = new InvokeEventArgs(pi, totalDigits,
digitsSoFar);

this.Invoke(new EventHandler(ShowProgress_invoke), new object[] {
args });



private void ShowProgress_invoke(object sender, EventArgs e)

{

// Call ShowProgress on what should now be the UI thread.

InvokeEventArgs iea = (InvokeEventArgs)sender;

ShowProgress(iea.pi, iea.digits, iea.digitsSoFar);

}

public class InvokeEventArgs : EventArgs

{

public string pi;

public int digits;

public int digitsSoFar;

public InvokeEventArgs(string _pi, int _digits, int _digitsSoFar)

{

pi = _pi;

digits = _digits;

digitsSoFar = _digitsSoFar;

}

}

-----


I'm not sure what the debugger has to do with anything.

Paul T.

"GT" <GT@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:38B59EC7-4DA2-4D11-BED7-2B55AEE6DF21@xxxxxxxxxxxxxxxx
Ok, let me get this straight:
Are you saying the Delegate's BeginInvoke() is not supported by the .Net
Compact Framework 2.0?
From the MSDN documentation I had the impression that both the Control's
and
the Delegate's BeginInvoke() are supported by the .Net CF 2.0. Which is
the
case?
The Visual Studio 2005 debugger does not complain about either.


"Paul G. Tobey [eMVP]" wrote:

The problem is that it's using BeginInvoke(). Not supported in .NET CF,
although it's in the class definition. It's throwing a
NotSupportedException, as expected.

Paul T.

"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:e5tfiu3yGHA.5048@xxxxxxxxxxxxxxxxxxxxxxx
The exception is in the thread. You have no handler, so when it
bubbles
up, it comes out at the top - Application.Run. Trust me, Run is
supported.

Sorry, but I'm not going to go to MSDN, download the sample and massage
it
into a device project just for the sake of helping you, and I doubt
anyone
else in the newsgroup will either. If you'd like to post the code,
then
we're happy to look at it for problems.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



"GT" <GT@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:11542385-2D84-4209-958C-C1FCF4C00BB9@xxxxxxxxxxxxxxxx
You will have to download the code from MSDN (see link in my original
post).
The example is small and nice so it shouldn't take too long to compile
and
get it running.
If you do so you will see that the described problem is caused by
the folowing call in AsynchCalcPiForm.cs >calcButton_Click :
calcPi.BeginInvoke((int)digitsUpDown.Value, null, null);
This call does however not throw any exceptions, because adding a
try{}
catch{Exception e} statement never causes the catch{} loop to be
executed.
Instead the VS2005 debugger indicates the NotSupportedException caused
by
Application.Run() in main() as before.
Please take a look at the source code. It would make this a lot
easier.

"<ctacke/>" wrote:

The exception is thrown elsewhere, probably in the worker thread
itself.
We
need to see more code. You could also try adding some try/catch
blocks
in
the thread proc to find it.

-Chris


"GT" <GT@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8EBA8255-D94D-4768-A6AF-B550C46133A0@xxxxxxxxxxxxxxxx
Hello

I'm having a problem running a C# multithreaded application on
Windows
CE
5.0.
The code I'm trying to execute is the source code of the MSDN
article:
"Safe, Simple Multithreading in Windows Forms, Part 3" , January
2003,
written by Chris Sells
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp).
The source files consist of 'AsynchCalcPi.cs' and
'NineDigitsOfPiAt.cs'
found in
winforms01232003_sample\ch13\LongRunningOperations\.
(For VS2005 users: Start a new Windows CE project with Compact
Framework
2.0
installed and do some copy and past to get it running).

The code demonstrates a thread safe 'message passing model', in
which
a
long
running operation (the calculation of n digits of pi) is performed
on
a
worker thread.
Everything in the source code is supported by the .Net Compact
Framework
2.0
so this code should run just as well on both Windows CE and Windows
XP. At
least so I thought.

The problem is that the application executes just fine on Windows
XP
(thanks
to MSIL), but I'm not able to get it running on Windows CE 5.0.
Strange,
isn't it?

What happens is that when i deploy the application from Visual
Studio
2005
on the Windows CE target device, the application starts up by
showing
a
form
in which you can type the number of decimals of pi you want to
compute
and
a
button to start and cancel the computations.
When pressing the start button a worker thread is started from the
thread
pool by calling BeginInvok and set to do the computations.

This is also where the application fails on Windows CE: When
pressing
the
start button a "NotSupportedException" is thrown and the Visual
Studio
2005
debugger indicates that this is caused by
Application.Run(new AsynchCalcPiForm());
in the main method.

This I don't understand. The Windows Form is simpy launched from
the
default
'Program.cs' file containing only the main method with the above
mentioned
statement.
What could be the problem here?
Why is this working on Windows XP but not Windows CE?

PS This question was posted under Mobile and Embedded
Development\Windows CE>Application Development but I was adviced to
post
it here instead.










.



Relevant Pages

  • Re: Problem with multithreaded C# app on Windows CE
    ... Unlike the .NET Compact Framework ... Framework 2.0 provides Control.BeginInvoke that asynchronously executes ... supported and I don't see any problems with them, but BeginInvoke isn't. ... "Safe, Simple Multithreading in Windows Forms, Part 3", January ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Getting hold of MessageWindow class
    ... Microsoft, if it's Microsoft code. ... Windows CE is *NOT THE SAME OPERATING ... What you need is a desktop-compatible class called MessageWindow ... MessageWindow class in the .NET Compact Framework does. ...
    (microsoft.public.windowsce.embedded)
  • Re: Problem with multithreaded C# app on Windows CE
    ... supported and I don't see any problems with them, but BeginInvoke isn't. ... digitsSoFar); ... public InvokeEventArgs(string _pi, int _digits, int _digitsSoFar) ... Start a new Windows CE project with Compact ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Capture text output of win app
    ... I have a custom, non-interactive, windows FTP application that, ... I used the following code to try to capture the output but "strOutput" ... Try the script below. ... I think what is happening is that after the Exec method line executes, ...
    (microsoft.public.scripting.vbscript)
  • Re: Need a good starting point for Windows CE
    ... understand better how Windows CE development works. ... I actually want to be able to develop "compact framework like ... SP2 installed, so I suppose I could install CF 2.0 SP2 without ... The operating system is built custom for the specific target device. ...
    (microsoft.public.windowsce.embedded)