I have an app that uses TabTip. When i want to close it i do this:
public void CloseTabTip()
{
foreach (Process pkiller in Process.GetProcesses())
{
if (pkiller.ProcessName.ToString() == "TabTip")
{
pkiller.Kill();
return;
}
}
}
And it trows an exception: access denied. Now the strange thing is that it only does that when i close the TabTip manually. And even stranger than that it only does that when i close it manually using the touch screen. Because when i close it using the mouse it works fine.
The function CloseTabTip is called when i click a button. If i click the button after manually closing the TabTip with touch screen it trows exception but if i close it using mouse it does not.
Now, i have pondered that it was because of this, however even if i wait some seconds for the process to close it still trows this exception. I am thinking this is a Windows bug since it only give an error when i close TabTib using the touch screen.
Any ideas on how to "fix" this? I know i can use a try catch statement but that is not the most correct way of doing things.
Running app in WIN10
Related
I have below line of code in my Windows application.
Below is the code which get trigger on click of tray icon click, and NotifyForm is normal Windows form.
ExceptionManager.Process(
() =>
{
if (notifyForm == null)
{
notifyForm = new NotifyForm();
notifyForm.Deactivate += (o, args) =>
{
notifyForm.Close();
};
notifyForm.Disposed += (o, args) =>
{
notifyForm = null;
};
}
if (!notifyForm.Visible)
{
notifyForm.ShowPopup();
}
else
{
notifyForm.Close();
}
}, "Policy");
Form is closing fine, when I run it through Visual Studio, if I navigate to Release folder and run exe explicitly, Deactivate event never fires. Help on this really appreciated.
Just for more information, notifyForm is notification pop up window which shows up above the tray, on click of tray icon.
Also, I have tried running application in release mode through visual studio, and it works fine. Only problem start happening when i run it outside of studio.
I have verified exe is up to date.
Edit - Basically I have form which i open on click of tray icon, and expecting clicking on desktop or some where should trigger deactivate event, which is not happening. Not sure why. :(
You need to compile your code in release to update the .exe!
EDIT: Maybe this link can help you
Thanks all for your help.
Calling below method, after showing pop up solved my issue.
notifyForm.Activate();
Thanks again.
Because VS runs code in a nice debug environment. Even in release mode. It keeps references alive longer than when running outside of the debugger.
Store notifyForm in a scope that will be alive at the time deactivate might be called. Easiest is a class variable.
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).
I can close all tab in chrome by use process thus:
Process[] chromeInstances = Process.GetProcessesByName("chrome");
if (chromeInstances.Length > 0)
{
foreach (Process p in chromeInstances)
{
p.Kill(); ;
}
}
But I want close one tab in chrome. It is possible?
According to this post, it is not possible: https://superuser.com/a/306715/68020
You can't close a tab by killing the process. The process represents a renderer that the main browser uses the execute and draw a page, which it then copies to the screen. The "Aw, Snap!" is what the browser displays when the renderer responsible for that tab crashes or is killed. The proper way to close the tab would ideally be via a command-line switch, but there is none that I know of at this time.
Also, as the comment describes,
there isn't a 1:1 relationship between tabs and renderer processes in the first place.
I have an ActiveX control written in C# which operates a scanner from the browser using WIA. Everything works fine except the WIA CommonDialog pops under the browser window. How can I get it to show up on top of the browser?
wiaDialog = new WIA.CommonDialog();
wiaImage = wiaDialog.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality, wiaFormatJPEG, false, false, false);
[Edit]
Thanks very much to Noseratio for putting me onto the right track. The suggestion to use BringWindowToTop invoked via a timer before popping up the dialog does not quite work. Instead the function to use is SetForegroundWindow. The code is as follows (invoked from a System.Timer.Timer prior to opening the scan dialog):
public static void scanDialogToTop(Object caller, EventArgs theArgs) {
scanner.theTimer.Stop();
foreach (Process p in Process.GetProcesses()) {
if (p.MainWindowTitle.StartsWith("Scan using")) {
SetForegroundWindow(p.MainWindowHandle);
break;
}
}
}
See this article for a more complete discussion.
It does not look like you can specify a parent window for ShowAcquireImage. If the caption of the popup window is static, you could use FindWindow to find the popup's handle. If ShowAcquireImage is a blocking call (doesn't return until the popup window is closed), before calling it you'd need to setup a timer and call FindWindow upon a timer event. I also suspect the WIA popup is created on a different thread (you could check that with Spy++). If that's the case, you could use the following hack to give the WIA popup window focus. Otherwise you just do BringWindowToTop.
I have a program that sends information in the background using Outlook. I want to avoid having the user deal with the "Outbox is not empty" message that appears when a user tries to close Outlook when an email is in the outbox. because in most cases the email in the outbox will not be an email they sent themselves. I am able to get a handle to the dialog, but I don't know which command to send to make it close. The only close command I know about will not work for a dialog box.
I must use Outlook to send the email due to security constraints.
I got the code from here which shows you how to trap the window events and sort through the window you want. I have found the window, and it helped me to stop the threads that might be sending email, but the dialog is still hanging there when I'm done.
The following code executes whenever an Explorer window is deactivated (i.e. loses focus)
void ExplorerWrapper_Deactivate()
{
IntPtr hBuiltInDialog = WinApiProvider.FindWindow("#32770", "Microsoft Office Outlook");
if (hBuiltInDialog != IntPtr.Zero)
{
// ok, found one
// let's see what childwindows are there
List<IntPtr> childWindows = WinApiProvider.EnumChildWindows(hBuiltInDialog);
// Let's get a list of captions for the child windows
List<string> childWindowNames = WinApiProvider.GetWindowNames(childWindows);
// now check some criteria to identify the build in dialog..
// here are the three child window names as cut and pasted from the code when debugging
// [0] = "There are unsent messages in your Outbox. To send messages, Outlook must remain running and connected to your e-mail server. Do you want to exit anyway?\r\n\r\nExiting in <0d> seconds"
// [1] = "Exit Without Sending"
// [2] = "Don't Exit"
if ((childWindowNames.Contains("There are unsent messages in your Outbox. To send messages, Outlook must remain running and connected to your e-mail server. Do you want to exit anyway?\r\n\r\nExiting in <0d> seconds")) &&
(childWindowNames.Contains("Exit Without Sending")) &&
(childWindowNames.Contains("Don't Exit")))
{
// at this point, we need to empty the outbox of any IkeNet email, and if the outbox is then empty, close the dialog
// and let outlook close as well
NotifyAdmin.SetShutdownRequested();
/// this close command does not seem to work for this window. supposedly it acts just like pressing
/// the <esc> key, which does nothing to the window when the program is running.
WinApiProvider.SendMessage(hBuiltInDialog,
WinApiProvider.WM_SYSCOMMAND, WinApiProvider.SC_CLOSE, 0);
}
}
}
The WinApiProvider.SC_CLOSE command will not work for this kind of window.
Any suggestions will be appreciated.
You could try using SendKeys to [tab][tab][enter] (or whatever the keystrokes are). I know it's not an elegant solution, but is this solution really elegant to begin with?
I would try sending a mouse click event to the Cancel button (or Close button -- I'm not familiar with the dialog box in question).