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();
}
As I said in my comment, try: Environment.Exit(0);
If that doesn't work, start with Cef.Shutdown();
https://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).
Related
this might sound dumb, I am new in WPF and in my application I open an additional window using Task.Factory.StartNew because the function runs in separate thread. After the debugging stops, this window stays open but without any images, only the text/clicking/animations are shown, but through this I can open other windows, as if the software was still running, which actually does through a process called "WPFSurface.exe", I assume it's some sort of debugging or just a bug but I can't find any information on google or stackoverflow. Here's the code that I use to create the window:
Task.Factory.StartNew(() =>
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
var controls = new ScreenControls(display);
controls.Show();
}));
});
I also close the application using this code (Yes it's binded correctly to Closed event)
private void MainWindow1_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
Thank you for your time!
1153/5000
I spent the last two days searching for a solution. Unfortunately, I found nothing, or at least nothing that would explain to me how to manage opening and closing windows.
I am new to programming, maybe that's the main problem.
But, my problem is:
I am doing a small WPF program using caliburn.micro and mwwm. The problem is opening and closing windows.
I would like to do a window management class or something like that, but I don't know how to aproach.
Could you explain to me step by step how to do it? I read the caliburn.micro documentation, but it doesn't explain how to do it.
In general, the situation looks like this:
I have a main window from which you can open several others. When i'm opening a window, the main window disappears. After closing that window, the main menu appears again. I did it with:
'''App.Current.MainWindow.Show();'''
I would like to manage all windows. Opening them and closing. I came to the point that I should do it with Iwindowmanager ... but how? What? Where? I have no idea. Hence the request for a step-by-step explanation.
ps. Forgive me my English.
edit:
757/5000
There's a problem with that, I don't have much code because I don't know how to go about it. And wherever I was looking, I couldn't find a hint.
But of course I will show what I have:
To open one window from the main menu I have this:
IWindowManager manager = new WindowManager();
public MenuView()
{
InitializeComponent();
}
private void ActionButton_OnClick(object sender, RoutedEventArgs e)
{
manager.ShowDialog( new FirstViewModel(), null, null);
this.Hide();
}
To close this window I'm using
App.Current.MainWindow.Show();
this.Close();
but if I use the first part of the code in a window other than the main menu, I don't know how to go back.
I'm dealing with a windows forms .NET application written in C# which needs to display a 3D pdf with all the associated features (rotate the object, change lights and so on). I'm using the AxAcroPDF COM control and it run smoothly. The problem is that when I try to close the form where the control is placed, sometimes it hangs for several seconds with no apparent reason while disposing the control. The 3D file I loaded during the tests is not particulary heavy. The very same file in the standalone adobe reader opens and closes with no particular delay.
I'm using the following code within the windows form closing event:
private void DrawingForm_FormClosing(object sender, FormClosingEventArgs e)
{
this.axAcroPDF.Dispose();
Application.DoEvents();
CoFreeUnusedLibraries(); }
[System.Runtime.InteropServices.DllImport("ole32.dll")]
static extern void CoFreeUnusedLibraries();
The interesting thing is that the form closes normally if the file is just displayed, but, when the object within the 3D file is rotated, it hangs during closing. When it hangs, the icon of a watch (the same shown in standalone Adobe PDF) is displayed. The hanging time is between 15-20 seconds.
I tried to display the file within the webbrowser control but I got similar results. What can be the cause of this problem?
I tried to search for alternative stable controls but I haven't found any with 3D support.
In FormClosing event handler add 2 lines:
this.Controls.Remove(yourAxAcroPDFControl);
yourAxAcroPDFControl = null;
Consider it a temporary solution until Adobe has an update. I checked Adobe SDK samples and those cause problems too, despite being written by Adobe themselves so we could expect them to consider it a problem.
This is how I fixed it - not great but it works!
protected override void WndProc(ref System.Windows.Forms.Message m)
{
// WM_CLOSE = 16
if (16 == m.Msg)
{
//closing
axAcroPDF1.LoadFile("UNLOAD_FILE_FOR_FUDGE");
// we need to wait a bit
System.Threading.Thread.Sleep(500);
}
base.WndProc(ref m);
}
The solution to the problem is not to call Dispose() but to let the operating system taking care of this instead. I tried and it works perfectly. Why? Maybe .NET calls crossing the COM boundaries cause the operation to slow down?
I use StatusStrip that contains ToolStripStatusLabel. OS - Windows 7, framework 2.0.
Usually all displayed normal, but sometimes ToolStripStatusLabel looks like black box:
I read that windows bug, but how I can fix it?
This is an obscure bug, triggered when you display the form with the Windows toolbar overlapping your StatusStrip. Moving the window away from the toolbar doesn't get the ToolStripItems on the status strip repainted properly. You'll find a bit of background in this forum post. There was a weak promise for a future fix for it, no idea if that ever happened. Probably not if you are running this on Win7.
You'll need to pay more attention to the position of the window, making sure that parts of it don't disappear underneath the toolbar. In general something you'd always consider, extra important as long as this bug doesn't get fixed. If you don't want to nail down the startup position (you ought to, users tend to like a window getting redisplayed where they last moved it) then simply change the form's StartPosition property to "CenterScreen".
This bug has never been fixed. It was in framework 2 and is still in framework 4.
The answer from Hans is a copy of the answer in social.msdn.microsoft.com.
But it is not helpful for me because "CenterScreen" does not solve the problem.
The cause of the problem is not the Windows Taskbar. The cause is a bug that does not draw the StatusStrip when the main Form is behind ANY other window at the first moment of drawing the StatusStrip. But this will also happen when you start the new process with Process.Start() from another process and the new process opens behind the window of another process.
I found a much better solution than the one proposed by Microsoft.
First I tried with
statusStrip.Invalidate();
but it does not work. So we need a stronger way to force Windows to redraw the StatusStrip. Important: The redrawing must happen when the Form with the StatusStrip is ALREADY in foreground! This is so easy that I don't understand why Microsoft does not suggest this method.
Timer mi_StatusTimer = new Timer();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
mi_StatusTimer.Interval = 500;
mi_StatusTimer.Tick += new EventHandler(OnTimerBugFix);
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
mi_StatusTimer.Start();
}
void OnTimerBugFix(object sender, EventArgs e)
{
mi_StatusTimer.Stop();
statusStrip.Hide();
Application.DoEvents();
statusStrip.Show();
}
Sometimes when our application launches it flashes orange in the taskbar. I don't think we explicitly wrote any code to do this but it still happens. Our program is a c# winforms app that sometimes takes a while to load. Any ideas what could be causing this and how I can prevent it?
I believe you can use MSDN's flashwinfo .
Edit - Here's some more info .
From my experience, if the application isn't the current application the user is using, but does something 'on its own' to update the UI(?) the system recognizes this and notifies the user by the orange flash thing.
So if your application is doing some long processing and the user clicks away to another application/window, they probably will get the orange flash.
A possible alternative would be to prevent the application from showing in the Taskbar until loading has completed.
So, something along the lines of:
// prevent from showing in the constructor (or via the designer)
public MyAppMainForm()
{
this.ShowInTaskbar = false;
// other initialization
}
// now you're ready to show in the Taskbar
private void MyAppMainForm_Load(object sender, EventArgs e)
{
this.ShowInTaskbar = true;
}