scoob
scoob

Reputation: 1379

C# Console Application still resident in memory after exit

I have an .net C# console application (not a service). it basically connects to a webservice, gets some xml files, copies those files to a few location on a drives, validates the xml, processes it and sends these objects to another web service.

However, when the main method exists (and the console window closes) I can still see the process in task manager.

I tried surrounding everything in the main method with a try, to catch an ApplicationException, and I still got nothing as to why the app crashes even though everything works smoothly otherwise...

Anybody has a clue as to where to begin to check for the faulty part?

Upvotes: 2

Views: 4319

Answers (5)

Scott Langham
Scott Langham

Reputation: 60391

If you're debugging the app, then I've seen the situation where Visual Studio creates a host exe named similar to your app with .vshost.exe at the end. It uses that control your app for a better debugging experience. This host exe stays around after you've finished debugging your program so that its waiting and ready so it can start a new debug session quickly.

Are you sure it's not this exe that's hanging around?

If you run your application without debugging, does it still hang around then?

Upvotes: 2

HasaniH
HasaniH

Reputation: 8402

As all the other answers have suggested you probably do have a lingering thread but its not necessarily one that you created explicitly, you may need to call Dispose or something similar on one or more of your objects

Upvotes: 1

JaredPar
JaredPar

Reputation: 755161

You almost certainly have an un-terminated thread in your application. As Jon said, attach with the debugger and see what threads are alive.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1502296

If the console window has closed, it seems very odd indeed that the process is still running. Can you attach to it in the Visual Studio debugger? (Obviously a debug build.)

Are you sure it's not a previous run which is still executing?

Upvotes: 2

leppie
leppie

Reputation: 117280

Look at Thread usage and async calls.

Upvotes: 4

Related Questions