1

I'm using https://github.com/gmamaladze/globalmousekeyhook for a program. The hook fires, but after some time there comes a CallbackOnCollectedDelegate and i don't have the knowledge for changing the code from github. I couldn't transform the help from into my code CallbackOnCollectedDelegate in globalKeyboardHook was detected

The failuremessage in Visual Studio (Language German) is:

CallbackOnCollectedDelegate ist aufgetreten. Message: Der Assistent für verwaltetes Debugging ""CallbackOnCollectedDelegate"" hat ein Problem in ""C:\Users\Admin\ownCloud\GRANT-ZIM\Code_Grant\Filter\GRANTExample\bin\x64\Debug\GRANTExample.vshost.exe"" festgestellt. Zusätzliche Informationen: Für den von der Garbage Collection gesammelten Delegaten vom Typ "Gma.System.MouseKeyHook!Gma.System.MouseKeyHook.WinApi.HookProcedure::Invoke" wurde ein Rückruf durchgeführt. Dies kann Anwendungsabstürze, Datenbeschädigung und -verlust zur Folge haben. Beim Übergeben von Delegaten an nicht verwalteten Code müssen die Delegaten von der verwalteten Anwendung beibehalten werden, bis sichergestellt ist, dass sie nie aufgerufen werden.

The used code is:

private IKeyboardMouseEvents m_GlobalHook;
public void Subscribe()
{
m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
m_GlobalHook.KeyUp += OnKeyUp;
}
Community
  • 1
  • 1
francisz
  • 21
  • 3
  • Can you translate the German? Some of us can not read it. – Athafoud Aug 30 '16 at 14:01
  • Well, crystal ball says that you have a bug in your code. A library like that will not trip this MDA, too many programmers have used it before. And it properly stores the delegate in a static variable so it is always referenced. But it is not perfect, it won't yell at you when you hook more than once. When you do, the first delegate object becomes unreferenced and can get collected. Fix your code, only hook once. – Hans Passant Aug 30 '16 at 14:20
  • I voted it as a duplicate but then I relized there is not enough information for it to be considered a duplicate so I re-opened the question, I would have voted to close for not having a clear example of the problem but I can't vote a 2nd time – Scott Chamberlain Aug 30 '16 at 16:32
  • 1
    The problem seems to be solved. The variable m_GlobalHook is static now. Now it works. Thanks for the answers. The hook was once, but the variable not static. – francisz Aug 31 '16 at 09:27

0 Answers0