Hybridzz Hybridzz - 2 months ago 18
C# Question

Application not ending properly and running in the background

I have a simple wpf application. But it is using CefSharp to open some links in chrome based browser. I found that once the main window of the application is closed, It is closed from the UI but it still runs in the background.

I tried adding additional code to force close it. but no hope. I think some components of cefsharp is not ending correctly. but not exactly sure on what is going wrong.

Used the below code and some other snippets too

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);


foreach (Window w in App.Current.Windows)
{
if (w.DataContext != this)
w.Close();
}
Application.Current.Shutdown();
}

Answer

As I said in my comment, try: Environment.Exit(0);

If that doesn't work, start with Cef.Shutdown();

http://stackoverflow.com/a/9050477/1274820

If you REALLY need it to close out you can also use Environment.Exit() but it is not graceful at all (more like ending the process).

Comments