19

I'm developing a console application that is supposed to run under WinCE 6.0 and WinCE 7.0. I'm using C#, Compact Framework 2.0 for different compatibility reasons.

My application is started by an external runtime called TwinCAT (from Beckhoff). Within this application, my teammate used a function block called nt_startProcess (documentation here) that is in charge of starting my application on demand.

My problem - Two different behaviors depending on the OS :

  1. When started manually (without TwinCAT) from a cmd line :

    My application behaves properly on both systems. It means that, the applications starts, displays "Hello World" and then returns to the cmd line.

  2. When started from TwinCAT :

    a) On WinCE 6.0, I can see a cmd line opening, displaying "Hello World" and shutting itself right after. Perfect behavior to me.

    b) On WinCE 7.0, I can see a cmd line opening, displaying "Hello World" but it remains open forever. This is my problem!

Code snippet :

using System;
using System.Collections.Generic;
using System.Text;

namespace MyBasicExample
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World");
    }
  }
}

Compilation information

In Visual Studio 2008, within the Project compilation's properties :

  • Plateform target : Any CPU

Additionnal note :

Please note that the computer who is running WinCE 6.0 is using a i486 processor while the one running WinCE 7.0 is using a Freescale ArmCortex process.

WinCE 6.0 :
WinCE 6.0

WinCE 7.0 :
WinCE 7.0

What I tried :

1) Using return 0; at the end of application.

Doesn't change anything on WinCE 7.0.

2) Using Environment.Exit(0);

Is not available in Compact Framework 2.0.

3) Using the property : IsBackground

Snippet :

// ... Same snippet as above except for the next line...
Thread.CurrentThread.IsBackground = true;
Console.WriteLine("Hello World");
// ...

4) From TwinCAT, calling a batch file (which calls my exe) instead of my exe.

Doesn't work with TwinCAT. I get an error of type "General Sub-Windows error".

5) Tested with the Compact Framework 3.5.

Same behavior.

6) Tested with another CX computer (model 2020) using Windows CE 7.0 and another processor architecture (Intel Pentium III Xeon Model A).

Same behavior.

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
Andy M
  • 5,945
  • 7
  • 51
  • 96
  • 3
    tried Environment.Exit(0) ? – Chaka Jul 28 '15 at 09:13
  • @Chaka I didn't think about that. I tried return 0; without much success... We're trying it right now. – Andy M Jul 28 '15 at 09:17
  • 1
    @Chaka I can't seem to have the Exit method in Compact framework 2.0. – Andy M Jul 28 '15 at 09:23
  • possible duplicate of [Force close Windows CE 5 app using C#](http://stackoverflow.com/questions/15967894/force-close-windows-ce-5-app-using-c-sharp) – Christian.K Jul 28 '15 at 09:29
  • @Christian.K Oh, I'll give it a careful look, thanks. – Andy M Jul 28 '15 at 09:29
  • @Christian.K It is not a dupplicate. Trying the different propositions doesn't help me in that case. Maybe it's because I have a console application and not a GUI one. I added a chapter with my attemps to clarify what I already tried. – Andy M Jul 28 '15 at 09:38
  • @AndyM That's fine - I wasn't sure either. – Christian.K Jul 28 '15 at 09:39
  • 1
    Never worked with WinCE, but with a generic "debugging hat" on, are you able to try either WinCE 6 on Arm, or WinCE 7 on Intel to see if the problem follows the version of WinCE or the platform? _I_ don't know what that would tell you, but it might give _someone_ a clue. – TripeHound Jul 28 '15 at 10:12
  • @TripeHound That is a nice proposition. However, I don't have other machines that would help me isolate either the OS or the processor. I don't have the equipment/software (nor the knowledge :)) to reinstall those specific machines. – Andy M Jul 28 '15 at 10:48
  • And no emulators? @AndyM – Patrick Hofman Jul 28 '15 at 10:51
  • @PatrickHofman I could emulate a WinCE6 or WinCE7 OS maybe. But in those cases, I'll be checking the "Manual" version which works in any cases. To fully reproduce my problem, I need the specific machines and TwinCAT, and I don't think I can emulate that ! I need TwinCAT to start my application from its code. – Andy M Jul 28 '15 at 10:54
  • @PatrickHofman Sure, thanks for proposing it! I'm pulling my hair trying to find a way to easily reproduce the trouble... It appears that when the application is started from the outside and opens the console I'll meet the trouble. If I start the same application manually and then the external application interacts with it, it can close it properly. – Andy M Jul 28 '15 at 11:01
  • It seems more a bug in TwinCAT than in your software. Are you reading from or writing to any output? Can the program be awaiting handling some input/output? – Patrick Hofman Jul 28 '15 at 11:03
  • @PatrickHofman My software uses a TwinCAT library to read/write variables in a ADS protocol (property of Beckhoff) that I share with the external machine. In summary, the machine raises flags to give me orders (such as starts command, closes yourself, ...). We've been reproducing the bug even with the small code I posted above so, the only part that could be messy is the part where they actually start my application with the "nt_startProcess". If not here, then it's a bug from either my code or Windows. I don't know. – Andy M Jul 28 '15 at 11:07
  • When trying `return 0;` did you change the (main-)method signature to return an int (instead of void)? Just a shot in the dark here, but maybe TwinCAT expects something like this. – KeyNone Jul 30 '15 at 07:31
  • @BastiM Thank you for your comment. I indeed added an int return to my Main. The problem is not around there ! Thanks anyway for your question ! – Andy M Jul 30 '15 at 07:42
  • 2
    I ran a test with WinCE7 and Intel architecture. I encounter the same problem. So your problem come from OS. Even with a GUI application (my idea was to redirect the console to a TextBox, and simulate a console application in GUI application), the form is closing, but the process doesn't end. If I launch my application (GUI or Console, CF 2.0 or 3.5, `Application.Exit(0)` or `return 0`) from cmd, I have to `ctrl+C` to end the process. – stephanejulien Aug 06 '15 at 13:03
  • @stephanejulien Interesting attempt to redirect console within GUI. Allright, thanks for the information. – Andy M Aug 06 '15 at 18:26

6 Answers6

1

try this code:

Environment.Exit(0);
Fatikhan Gasimov
  • 903
  • 2
  • 16
  • 40
1

Try this:

Tools > Options > Debugging > Automatically Close the Console When Debugging Stops

Kirill
  • 41
  • 3
0

Are you putting you .exe file in Arguments property of ProcessStartInfo ? If you must do that, I believe that you're using CMD in FileName property, so you must use /K before your .exe name. Or just put in FileName the .exe path. You can clarify a lot if you put the code that calls your application.

Caverna
  • 461
  • 9
  • 16
0

Try calling Application.Exit

This works in windowed applications, and may force the console window to close.

aldo
  • 2,927
  • 21
  • 36
tones
  • 1
0

I had exactly the same problem. Running console app on Beckhoff PLC which never closed.

Instead of creating Console app I created Windows App. My code stayed the same as for console app. I just commented out:

// Application.Run(new Form1());

Seems now codes run without opening a form.

damir
  • 11
  • 3
0

My collegue had a similar problem on a Windows CE 6.0 panel, where the console didn't close after running a simple c# program. He solved the issue by not using any Console. command in the application. With this approach, the application did execute without even opening the windows ce compact conosle.

dabbinavo
  • 1
  • 1