jimradford / superputty

The SuperPuTTY Window Manager for putty sessions
https://www.facebook.com/superputty
MIT License
1.91k stars 320 forks source link

SuperPuTTY is unresponsive when becoming active window #721

Open arpad-boros opened 5 years ago

arpad-boros commented 5 years ago

Describe the bug Hi! I'm using SuperPuTTY 1.4.0.9. When I'm changing over from an another application to SuperPuTTY, I experience about ~2 seconds of unresponsiveness, and also high CPU load at that time. Installed PuTTY version: 0.70 64-bit

When I start the application without administrator rights, the following is visible during the application switching: 2018-12-05 17:02:02,659 WARN DesktopWindow - Could not get exe. error=Access is denied, process=617536 2018-12-05 17:02:05,043 INFO EventWindowActivator - [595828] Activating Main Window - current=(C:\Program Files\Notepad++\notepad++.exe) 2018-12-05 17:02:05,059 INFO ApplicationPanel - [595828] ReFocusPuTTY - puttyTab=mySSH, caller=WinEventProc-FG, AltTab=False, result=True 2018-12-05 17:02:05,059 DEBUG frmSuperPutty - [7412590] Activated 2018-12-05 17:02:05,516 WARN ctlPuttyPanel - Unable to SetFocusToChildApplication, mySSH

With administrator rights: 2018-12-05 17:03:20,986 INFO EventWindowActivator - [595920] Activating Main Window - current=(C:\Program Files\Notepad++\notepad++.exe) 2018-12-05 17:03:21,002 INFO ApplicationPanel - [595920] ReFocusPuTTY - puttyTab=mySSH, caller=WinEventProc-FG, AltTab=False, result=True 2018-12-05 17:03:21,002 DEBUG frmSuperPutty - [1246344] Activated 2018-12-05 17:03:21,457 WARN ctlPuttyPanel - Unable to SetFocusToChildApplication, mySSH

This "Unable to SetFocusToChildApplication" message seems to be suspicious for me.

Desktop (please complete the following information):

adamhj commented 5 years ago

I got the same problem. OS: Windows 7 64-bit

traceback for the "Could not get exe" error:

SuperPutty.exe!SuperPutty.Utils.DesktopWindow.GetProcessExe(System.Diagnostics.Process process) Line 74 C# SuperPutty.exe!SuperPutty.Utils.DesktopWindow.GetDesktopWindows.AnonymousMethod__0(System.IntPtr hWnd, int lParam) Line 47 C# [External Code] SuperPutty.exe!SuperPutty.Utils.DesktopWindow.GetDesktopWindows() Line 64 C# SuperPutty.exe!SuperPutty.Utils.DesktopWindow.GetFirstDesktopWindow() Line 91 C# SuperPutty.exe!SuperPutty.ApplicationPanel.UpdateForeground() Line 235 C# SuperPutty.exe!SuperPutty.ApplicationPanel.WinEventProc(System.IntPtr hWinEventHook, uint eventType, System.IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) Line 208 C# [External Code] SuperPutty.exe!SuperPutty.Program.Main(string[] args) Line 92 C#

It seems that when a putty window, which is managed by superputty, get focus, SetWinEventHook callback calls UpdateForeground, which calls SuperPutty.Utils.DesktopWindow.GetFirstDesktopWindow. The problem is that this helper function will enumerate ALL windows hwnd running on the system and extract some information, this causes seconds of freeze on a system with many windows opened. It is odd that, all these time taking jobs to enumerate and extract windows information, is only to find the top most window, and print its title, process name, etc. into debug log, I didn't found other use of these data in the source code. And it seems to me that all those code in Utils/DesktopWindowHelper.cs is useless, or useful for debug purpose only.

I have write a simple patch(66c9488dfed1419b5ef0bd5a8f550b98bf19bcf0) to bypass this meaningless enumerating process, but I'm not sure will this break any intended behavior

jimradford commented 5 years ago

@adamhj for debut purposes most likely. I'm not oposed to a pull request that adds an "advanced debugging" checkbox to Settings.

-- Jim

Mtbarros commented 5 years ago

Hi, I am also having this issue on Windows 10 Pro 64-bit

arpad-boros commented 5 years ago

My workaround was to switch over to use putty as standalone, as this issue makes hard to use superputty in a productive way.

Reiner030 commented 5 years ago

Since last big Windows 10 update (there is only 64bit left?) I have this problem also more often (I got update delay till Nov/Dec because of Lenovo bug ... and additionally my update tries still crashed because of permanent activated NVidia graphic card instead of using default Intel one).

Additional there was also a problem like in #182 before the update that at every usage of the context menu it takes about 4-7s to open it - independent if I have only one or up to 10 sessions open. First I used PuttyTray but because of outdated client / possible incompatibilities I switched to default Putty without solving the delay problem. Before I uses a very old copy of Puttytray < 2015 because the project had died and when I found it reborn already latest version was out.

sulisu commented 5 years ago

I found a workaround with Autohotkey. I am using 1.4.0.9 with kitty.

When superputty start to be unresponsive, I run the following code with Autohotkey to bring it up. It will make SuperPuTTY window on top immediately, then send the FocusActiveSession hotkey to the activated window to make it ready for input. I reassigns the F2 key to this function.

I now make it a shortcut on task bar. If there is no running SuperPuTTY process, it will launch it as a normal shortcut.

if WinExist("SuperPuTTY ahk_exe SuperPutty.exe") {
    WinActivate  ; Uses the last found window.
    Sleep 100
    WinActivate  ; Uses the last found window.
    SendInput {F2}
}
else {
    Run, "ProgramPath\SuperPutty.exe", ProgramPath
}

Since SuperPutty has saved me from a lot troubles caused by floating console windows everywhere, a special but quick method to active it won't bother me too much. I hope author can now put his precious time on other more fun things.

My workaround was to switch over to use putty as standalone, as this issue makes hard to use superputty in a productive way.

sulisu commented 5 years ago

I have tried attach putty and kitty windows to cmder, it seems more responsive than SuperPuTTY. Maybe author can reference some code from cmder. reference https://www.thecrumb.com/2013/03/04/configuring-conemu-and-putty/ https://superuser.com/questions/750795/how-to-auto-attach-any-putty-or-kitty-console-to-conemu

sektomek commented 5 years ago

Hi

I'm also troubled by this issue. Can some give step by step procedure how to incorporate the patch mentioned by adamhj into SuperPutty ?

I have write a simple patch(66c9488) to bypass this meaningless enumerating process, but I'm not sure will this break any intended behavior

I guess I need to download the source code and then compile with csc.exe. But I'm new to this tool and here is what I'm getting: csc.exe /t:exe /out:SuperPuTTY.exe *.cs

ctlApplicationPanel.cs(26,7): error CS0246: The type or namespace name 'WeifenLuo' could not be found (are you missing a using directive or an assembly reference?) ctlApplicationPanel.cs(28,7): error CS0246: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?) ctlApplicationPanel.cs(31,18): error CS0234: The type or namespace name 'Utils' does not exist in the namespace 'SuperPutty' (are you missing an assembly reference?) ctlPuttyPanel.cs(28,7): error CS0246: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)

adamhj commented 5 years ago

@sektomek

You should not download only the patched file, but the whole project instead, then patch the project with the patch. It's recommend to use a git client to do all of these. Maybe you should take some tutorials, such as https://guides.github.com/.

And in fact after using of my patched version of SuperPuTTY for days, I find another problem, the SuperPuTTY window may fails to restore when clicking the taskbar icon after it's minimized. and this bug is hard to reproduce. It seems happens randomly, makes it very hard to trace down where the problem is. So I'm not sure is it introduced by my patch or something else. At last I gave up and turned to use Putty Session Manager to mange my putty sessions.

sektomek commented 5 years ago

Hi

I did downloaded the whole project. What are the steps to compile it once downloaded ?

Can you share your superputy.exe with the patch in it. - That is quickest i guess.

Tomek Sek

On Sat, May 4, 2019 at 3:47 PM Adam.H notifications@github.com wrote:

@sektomek https://github.com/sektomek

You should not download only the patched file, but the whole project instead, then patch the project with the patch. It's recommend to use a git client to do all of these. Maybe you should take some tutorials, such as https://guides.github.com/.

And in fact after using of my patched version of SuperPuTTY for days, I find another problem, the SuperPuTTY window may fails to restore when clicking the taskbar icon after it's minimized. and this bug is hard to reproduce. It seems happens randomly, makes it very hard to trace down where the problem is. So I'm not sure is it introduced by my patch or something else. At last I gave up and turned to use Putty Session Manager to mange my putty sessions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jimradford/superputty/issues/721#issuecomment-489328645, or mute the thread https://github.com/notifications/unsubscribe-auth/AGURUW55AOW4WTKSX7274NLPTWHYPANCNFSM4GIMHHVQ .

adamhj commented 5 years ago

@sektomek try this: https://github.com/adamhj/superputty/releases/tag/1.4.0.9.freeze_fix_patched It's a patched version based on code of 1.4.0.9. There are new commits in the main project, but since there is no new release yet, I don't merge them in.

sektomek commented 5 years ago

Hi

I have gave it a try, but I'm getting error restoring superputy window,.

On Sun, May 5, 2019 at 5:07 AM Adam.H notifications@github.com wrote:

@sektomek https://github.com/sektomek try this: https://github.com/adamhj/superputty/releases/tag/1.4.0.9.freeze_fix_patched It's a patched version based on code of 1.4.0.9. There are new commits in the main project, but since there is no new release yet, I don't merge them in.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jimradford/superputty/issues/721#issuecomment-489384543, or mute the thread https://github.com/notifications/unsubscribe-auth/AGURUWZEWKRNCNGMCBRULOLPTZFOVANCNFSM4GIMHHVQ .

meehowPL commented 4 years ago

Hey guys,

I downloaded a compiled fixed version posted by @adamhj. Indeed it works way better and actually I'm not experiencing the delays when switching between any application and SuperPutty or between SuperPutty windows. There's one item noticed though:

After switching the Putty windows in SuperPutty, a magic 'Left Alt' comes into play for a fraction of a second. I use AutoHotkey for some automatons, for example I have a command mapped under 'Left Alt + c'. When I'm in SuperPutty and use mouse to switch between open Putty windows and press 'c' character immediately, the result of AutoHotkey's 'Left Alt + c' is put into the Putty window and not onlt the 'c' character. If I do the same with some delay i.e. switch to another Putty window, wait a sec and start typing, all is OK then.

Any clues what can be the reason of this momentary 'Left Alt' when activating Putty window with mouse?

Thanks!

Michal

dburnett63 commented 1 year ago

I had an issue where super putty would launch but all of these old sessions would try to start. None of my sessions would appear on the right side and putty windows were small and unusable. The program was generally unusable. It took a bit to find but in your "documents" folder there is a SuperPutty folder where sessions are stored. Find the one called AutoRestoreLayout.XML and delete that file. Once I did that Putty started fine.

rudolphos commented 1 year ago

I'm getting similar errors after launching superputty from gns3. In sequential order:

---------------------------
putty command line error.
---------------------------
Could not start putty session: Arguments passed to commandline invalid.
Process Window Not Found
---------------------------
Process window not found.
Failed to create session panel
---------------------------
Error trying to create session Cannot access a disposed object.
Object name: 'ctlPuttyPanel'.

GNS3 console config: C:\Program Files (x86)\SuperPuTTY\SuperPutty.exe -telnet "%h -P %p -wt \"%d\"" This is when using putty_standalone.exe from GNS3 in SP settings. SuperPutty version: 1.5.0.0

This is when using latest putty.exe in Tools>Options >General settings:

PuTTY Command Line Error
---------------------------
unknown option "-wt"
putty command line error.
---------------------------
Could not start putty session: Arguments passed to commandline invalid.
Process Window Not Found
---------------------------
Process window not found.

And:

Unhandled Error
---------------------------
CurrentDomain_UnhandledException: IsTerminating=True, ex=System.InvalidOperationException: Value Close() cannot be called while doing CreateHandle().
   at System.Windows.Forms.Form.Close()
   at SuperPutty.SuperPuTTY.<>c__DisplayClass40_0.<OpenProtoSession>b__0(Boolean <p0>)
   at System.Diagnostics.Process.OnExited()
   at System.Diagnostics.Process.RaiseOnExited()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)