473,766 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Console exe continues to run after exiting all of my code

I have a .NET console application that is kicked off by a .NET Windows
service. They communicate via .NET Remoting, although there isn't much
communication between the two while the console app is running. There can
be, and are typically, several instances of the console app running at the
same time communicating back to the service.

The console app creates a delegate to do some work while the main thread
waits on a ManualResetEven t to be signaled (ManualResetEve nt.WaitOne()).
When the delegate is done, it calls Set on the ManualResetEven t, the WaitOne
returns and the app exits - 99.99999% of the time.

This is very hard to reproduce, but every once in a while, once the console
app has finished running all of the code I put in it, but it continues to run
- and at 45-50% of the CPU. Here is my Main:

[STAThread]
static void Main(string[] args)
{
try
{
// Create the one and only TsDPDllHost class for this process
WriteTrace( "1 Creating object" );
MyClass myClass = new MyClass);
WriteTrace( "2 calling myClass.Run" );
myClass.Run();
WriteTrace( "3 Exiting" );
}
catch(Exception e)
{
WriteTrace( "4 Exiting - ERROR e.Message=" + e.Message );
}
}

No exceptions are thrown and the trace statements #1, 2, and 3 are written
to a log file. TaskManager says the console app has 1 thread left, but
trying to attach to it with a debugger never comes back. Using SysInternals'
Process Explorer shows the following as the stack on the 1 thread:

ntdll.dll!RtlFr eeHeap+0x67
!TipUnloadProje ct+0xc2d
!TipUnloadProje ct+0xba7
!TipUnloadProje ct+0x741
!BASIC_DISPINTE RFACE_GetTICoun t+0xd5bf
ntdll.dll!LdrIn itializeThunk+0 x29
ntdll.dll!LdrSh utdownProcess+0 x142
!IsValidLocale+ 0x8eb
!ExitProcess+0x 14
!GetCompileInfo +0x6553c
!CorExeMain+0x7 9
!RegisterWaitFo rInputIdle+0x49

Has anybody seen anything like this or know what might be going on?

Thanks,
Tim

Feb 1 '06 #1
5 3863
Hello Tim,

From the problem description, it is hard to isolate the problem without
detailed debug information. I suggest you create more trace information in
the application to write down the console application process ID and thread
ID.

Besides, is the windows service always running well?

Another troubleshooting way is try to simply your console application as
much as possible to isolate which part the problem exists.

By the way, please refer to the follow topic on how to debug your windows
service application:
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbtskdebuggings erviceapplicati ons.asp
It may also be helpful for this scenario.

Generally speaking, this kind of problem (hard to repro) is better to be
troubleshooted by debugging tools. But let us try the above ways first to
see whether we can get some more information first.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://msdn.microsoft.com/subscripti...gednewsgroups/

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 1 '06 #2
Yan-Hong,

Thank you for your response. I am sorry it has taken me so long to get back
to this. I have done what you suggested and the main thread is what is
hanging. The Windows service is always running, but it is functioning
normally. It is a child process of that service that is hanging in its main
thread. The stack trace this time is:

ntdll.dll!strch r+0x101
ntdll.dll!RtlIn itializeSListHe ad+0x2ee0
!TipUnloadProje ct+0xc2d
!TipUnloadProje ct+0xba7
!TipUnloadProje ct+0x741
!BASIC_DISPINTE RFACE_GetTICoun t+0xd5bf
ntdll.dll!LdrIn itializeThunk+0 x29
ntdll.dll!LdrSh utdownProcess+0 x142
!IsValidLocale+ 0x8eb
!ExitProcess+0x 14
!GetCompileInfo +0x6553c
!CorExeMain+0x7 9
!RegisterWaitFo rInputIdle+0x49

From the stack trace, it looks like it is out of all my code and is trying
to shutdown the process. I have tried attaching to the process using VS.NET
2003's debugger, but after selecting the process, control is never returned
to the IDE.

Yes, I agree it is better to use debugging tools, but when the debugger
doesn't come back, it is kind of hard. Are there any other suggestions or
debugging tools I could use?
Feb 15 '06 #3
Hi ecydba,

Thanks for your feedback.

Actually, I am confused by your statement. Let's do some scoping first:

You have several console .Net applications may communicate with single .Net
windows service application through .Net Remoting. You console application
main thread use a threadpool asynchronized delegate to do the background
processing(at the meantime, the main console thread wait and sleep on a
ManualResetEven t). After the background delegate thread finished all the
work, it set the ManualResetEven t, which wake up the main console thread
and the application runs through all the code and exits. But, sometimes,
you find the console application did not exit at all. If I have
misunderstood you, please feel free to let me know.

Regarding this scenario, there are 2 threads in your console application,
main GUI thread and threadpool background delegate thread.
I have done what you suggested and the main thread is what is
hanging. Can you confirm the "main thread" you are referring is console application
"main thread" or .Net service application "main thread"?
It is a child process of that service that is hanging in its main
thread.

I am confused by this statement. In your first post, you did not memtion
any child process. So we need some context information regarding this child
process. Also, can you confirm whether the hang lies in the client console
application or certain child process main thread?

At last, in call stack, for each stack frame, in front of the "!" there
should be a module name. But in the call stack you listed, there are
certain stack frame without any module name listed. Can you give it a
check?

Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 16 '06 #4
Your synopsis is correct, except for the fact that in my original post, I
mentioned the .NET service kicks off/creates/spawns the .NET console app,
which I consider a child app.
Regarding this scenario, there are 2 threads in your console application,
main GUI thread and threadpool background delegate thread.
That is correct.
I have done what you suggested and the main thread is what is
hanging.

Can you confirm the "main thread" you are referring is console application
"main thread" or .Net service application "main thread"?


I confirmed it is the main thread of the console app. There is nothing
wrong with the .NET service app.
It is a child process of that service that is hanging in its main
thread.

I am confused by this statement. In your first post, you did not memtion
any child process. So we need some context information regarding this child
process. Also, can you confirm whether the hang lies in the client console
application or certain child process main thread?


The .NET service spawns the (child) .NET console apps. The hang is in the
client (child) console app's main thread.
At last, in call stack, for each stack frame, in front of the "!" there
should be a module name. But in the call stack you listed, there are
certain stack frame without any module name listed. Can you give it a
check?


The frame stack I posted is all I can get from Process Explorer
(procexp.exe/SysInternals). When I try to attach to the child console app
process with VS.NET 2003 debugger, control is never returned to me. So I am
never given a chance to hit the BREAK button to break execution of the app to
see what kind of stack trace VS.NET would give. I have also tried using
Windbg to attach to the process but basically have the same results. When I
key in any of the commands to display the call stack ('k', 'kb', 'kp', 'kv',
'kd'), it says it can't. Sending a break command in windbg times out. So,
the best I can give you is what procexp have given me. If you know of a
better way, I will be happy to try it.

Thanks,
Tim
Feb 16 '06 #5
Hi Tim,

Thanks for your feedback.

Yes, with your further feedback I understand your problem context much
better now.

First, I have some questions regarding your issue: what account your
service is running under? Because it invokes the console application, the
console application should run under the same account as the service. So I
am curious about the session&winstat ion information your console
application was associated with. You can use "Session Viewer" writen by
"Keith Brown" to get the session and winstation information, which can be
downloaded in the link below:
http://www.develop.com/technology/re...42b-504f-4959-
9e18-332848ebfb74

Based on the call stack, your main thread hangs in the ExitProcess API
calling.

Currently, I am not sure why the windbg can not dump out the call stack for
the main thread. Maybe we should use ADPlus to obtain a hang dump of the
console application.

After getting the dump file, you can use windbg to load it and analysis it.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Feb 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
19016
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app it works fine. Any idea? using System; using MyTestApp.Messaging; using MyTestApp.BusinessLayer; using System.Threading;
17
4235
by: MumboJumbo | last post by:
Hi I have a really basic question hopefully some can help me with: Can you write a (i.e. one) C# project that works from the cmd line and gui? I seems if i write a GUI app it can't write to console using System.Console.WriteLine if thge project has its "Output Type" to "Windows Application". However I can write to stdio if i set output type to "Console Application". When I do this I unfortunately get a "console box" as well
1
2523
by: Peter Oliphant | last post by:
I have a C++ Console application being written using VS C++.NET 2005 Express. It never crashes and seems to be working just fine. However, when I close the application via the Console 'X' exit button in upper right corner of its dialog box I get the following exit code: "The program ' MyApplication.exe: Managed' has exited with code -1073741510 (0xc000013a)." If I close it via the 'X' in the application form it exits with exit code 0:
10
8496
by: shiry | last post by:
Hi, I need to do some important cleanup before my console application exists. I used the console ctrl event. This is working well and it fires for all cases, including the CTRL_CLOSE_EVENT (if I close the application from the X botton). But on the contrary to what the MSDN indicates (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003OCT.1033/dllproc/base/handlerroutine.htm), ending my process from the task manager did not fire the CTRL_CLOSE_EVENT....
6
19778
by: Aart Nicolai | last post by:
Hi all, I have developed a vb.net console application which will run some code every seconds. To get this working I used a timer "System.Timers". When I start my console application it exits within a second. So I added the line: "Console.Read()". Everything seemes to run fine but after a few days the application stopped. Without an error. I think it has something to do with the lifetime of the "Console.Read()". Is this right?
9
64461
by: Susan Rice | last post by:
I'm running a simple win32 console application and I want to impliment a "Press any key to continue", so I print that prompt, and then what's the easiest way to impliment reading any key? Do I use 'getchar', or 'gets', or some get function? or 'cin', or what's an easy way? What I want is the program to pause before exiting so the user can read whatever messages there are before the console window disappears.
6
4904
by: vijai.kalyan | last post by:
Hello, I wrote a trivial program to set the console title in a console application. Here is the code:- namespace myns { class SetTitle { static void Main ( string args )
6
2514
by: Ant | last post by:
Hi all, I'm putting together a simple help module for my applications, using html files stored in the application directory somewhere. Basically it sets up a basic web server, and then uses the webbrowser module to display it in the users browser. I have it set up to call sys.exit(0) if the url quit.html is called, but for some reason (on Windows XP via the cmd.exe shell) python won't let me have the console back. I get the System Exit...
4
5695
by: federico | last post by:
Hello, I am trying to setup a Visual Basic "Console" application for searching Outlook folders. To this end I am trying to implement a Handler for the Outlook.Application.AdvancedSearchComplete Event. The problem I have is that the application finishes and exits before the AdvanceSearch, so the Event Handler in never called. If I delay the end of the application, for example, by having message box right after the call to AdvancedSearch,...
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
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.