c# - Can't kill a still running Outlook instance -
i'm trying kill still running outlook instance(used in application not outlook itself), call following in deconstructor
//_app = microsoft.office.interop.outlook.application _app.quit(); marshal.finalreleasecomobject(_app); marshal.finalreleasecomobject(_app.session); gc.waitforpendingfinalizers(); gc.collect(); but nothing helps, there more ways kill , if so, how?
first import of user32.dll done able use getwindowthreadprocessid
then kill method receives outlook app parameter , obtains process , kills it
public static class outlookkiller { [dllimport("user32.dll", entrypoint = "getwindowthreadprocessid", setlasterror = true, charset = charset.unicode, exactspelling = true, callingconvention = callingconvention.stdcall)] private static extern long getwindowthreadprocessid(long hwnd, out long lpdwprocessid); public static void kill(ref microsoft.office.interop.outlook.application app) { long processid = 0; long apphwnd = (long)app.hwnd; getwindowthreadprocessid(apphwnd, out processid); process prc = process.getprocessbyid((int)processid); prc.kill(); } }
Comments
Post a Comment