VB application leaves hunging background Excel process up till application exits
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a very small and simple VB application developed on Visual Studio whose role is to:
- Open an Excel Workbook (which includes some calculations formulae),
- Feed into the INPUT cells the values of the parameters,
- Retrieve from a pre-defined cell the value of the result.
Excel is run without human interface (i.e. Excel_Application.Visible = False
).
Upon completion of the calculation (and retrieval of the result) the following commands are executed:
:
Excel_Workbook.Close(False)
Excel_Workbook = Nothing
Excel_Application.Quit()
Excel_Application = Nothing
:
Even after these statements are executed, when looking at the Task Manager an Excel process is shown. This process is removed when the application is asked to end (e.g. click at the "X" button of the window).
It should be noted that, if I turn on the graphical interface, the icon from the taskbar does disappear after Excel_Application.Quit()
but the background process still remains.
I need the ability to leave no background process without closing the application.
I search the web and found a number of suggestions, none of them work.
excel vb.net
add a comment |
I have a very small and simple VB application developed on Visual Studio whose role is to:
- Open an Excel Workbook (which includes some calculations formulae),
- Feed into the INPUT cells the values of the parameters,
- Retrieve from a pre-defined cell the value of the result.
Excel is run without human interface (i.e. Excel_Application.Visible = False
).
Upon completion of the calculation (and retrieval of the result) the following commands are executed:
:
Excel_Workbook.Close(False)
Excel_Workbook = Nothing
Excel_Application.Quit()
Excel_Application = Nothing
:
Even after these statements are executed, when looking at the Task Manager an Excel process is shown. This process is removed when the application is asked to end (e.g. click at the "X" button of the window).
It should be noted that, if I turn on the graphical interface, the icon from the taskbar does disappear after Excel_Application.Quit()
but the background process still remains.
I need the ability to leave no background process without closing the application.
I search the web and found a number of suggestions, none of them work.
excel vb.net
1
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
1
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26
add a comment |
I have a very small and simple VB application developed on Visual Studio whose role is to:
- Open an Excel Workbook (which includes some calculations formulae),
- Feed into the INPUT cells the values of the parameters,
- Retrieve from a pre-defined cell the value of the result.
Excel is run without human interface (i.e. Excel_Application.Visible = False
).
Upon completion of the calculation (and retrieval of the result) the following commands are executed:
:
Excel_Workbook.Close(False)
Excel_Workbook = Nothing
Excel_Application.Quit()
Excel_Application = Nothing
:
Even after these statements are executed, when looking at the Task Manager an Excel process is shown. This process is removed when the application is asked to end (e.g. click at the "X" button of the window).
It should be noted that, if I turn on the graphical interface, the icon from the taskbar does disappear after Excel_Application.Quit()
but the background process still remains.
I need the ability to leave no background process without closing the application.
I search the web and found a number of suggestions, none of them work.
excel vb.net
I have a very small and simple VB application developed on Visual Studio whose role is to:
- Open an Excel Workbook (which includes some calculations formulae),
- Feed into the INPUT cells the values of the parameters,
- Retrieve from a pre-defined cell the value of the result.
Excel is run without human interface (i.e. Excel_Application.Visible = False
).
Upon completion of the calculation (and retrieval of the result) the following commands are executed:
:
Excel_Workbook.Close(False)
Excel_Workbook = Nothing
Excel_Application.Quit()
Excel_Application = Nothing
:
Even after these statements are executed, when looking at the Task Manager an Excel process is shown. This process is removed when the application is asked to end (e.g. click at the "X" button of the window).
It should be noted that, if I turn on the graphical interface, the icon from the taskbar does disappear after Excel_Application.Quit()
but the background process still remains.
I need the ability to leave no background process without closing the application.
I search the web and found a number of suggestions, none of them work.
excel vb.net
excel vb.net
edited Nov 22 '18 at 5:16
FDavidov
asked Oct 19 '17 at 8:54
FDavidovFDavidov
2,39741230
2,39741230
1
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
1
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26
add a comment |
1
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
1
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26
1
1
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
1
1
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26
add a comment |
1 Answer
1
active
oldest
votes
I would suggest to get the process of created Excel application and then close it:
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Sub UseExcel()
Dim xlApp = New Excel.Application With {.Visible = True}
Dim xlHwnd = New IntPtr(xlApp.Hwnd)
Dim proc = Process.GetProcesses().First(Function(p) p.MainWindowHandle = xlHwnd)
'// Do the work with Excel...
'// In the end:
proc.Kill()
End Sub
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46826146%2fvb-application-leaves-hunging-background-excel-process-up-till-application-exits%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would suggest to get the process of created Excel application and then close it:
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Sub UseExcel()
Dim xlApp = New Excel.Application With {.Visible = True}
Dim xlHwnd = New IntPtr(xlApp.Hwnd)
Dim proc = Process.GetProcesses().First(Function(p) p.MainWindowHandle = xlHwnd)
'// Do the work with Excel...
'// In the end:
proc.Kill()
End Sub
add a comment |
I would suggest to get the process of created Excel application and then close it:
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Sub UseExcel()
Dim xlApp = New Excel.Application With {.Visible = True}
Dim xlHwnd = New IntPtr(xlApp.Hwnd)
Dim proc = Process.GetProcesses().First(Function(p) p.MainWindowHandle = xlHwnd)
'// Do the work with Excel...
'// In the end:
proc.Kill()
End Sub
add a comment |
I would suggest to get the process of created Excel application and then close it:
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Sub UseExcel()
Dim xlApp = New Excel.Application With {.Visible = True}
Dim xlHwnd = New IntPtr(xlApp.Hwnd)
Dim proc = Process.GetProcesses().First(Function(p) p.MainWindowHandle = xlHwnd)
'// Do the work with Excel...
'// In the end:
proc.Kill()
End Sub
I would suggest to get the process of created Excel application and then close it:
Imports System.Diagnostics
Imports Excel = Microsoft.Office.Interop.Excel
Sub UseExcel()
Dim xlApp = New Excel.Application With {.Visible = True}
Dim xlHwnd = New IntPtr(xlApp.Hwnd)
Dim proc = Process.GetProcesses().First(Function(p) p.MainWindowHandle = xlHwnd)
'// Do the work with Excel...
'// In the end:
proc.Kill()
End Sub
edited Nov 22 '18 at 8:42
answered Nov 22 '18 at 8:35
JohnyLJohnyL
3,73811025
3,73811025
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46826146%2fvb-application-leaves-hunging-background-excel-process-up-till-application-exits%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Maybe this post can help stackoverflow.com/q/158706/1050927, the top 3 (by votes) should help
– Prisoner
Oct 19 '17 at 9:55
1
Excel cannot quit until all the interface references are released. That happens when the garbage collector runs, like it will when your vb.net app continues to do useful work. Or when you close it. So a rough diagnostic is that your vb.net app doesn't do anything useful anymore. Yes, you might as well quit it. Or call GC.Collect if want to force it. Be careful where you put it however, it should go in the code that calls this method or it won't do the job when you debug.
– Hans Passant
Oct 19 '17 at 10:46
Thank you @HansPassant for your comment. I should add some more details... The posted code is part of a class that will eventually be part of a DLL. The DLL will be assembled into a SQL SERVER function to be invoked by a stored procedure and hence the GC cannot be invoked from the calling procedure. Meaning, the whole thing must be self-contained within the DLL. One additional observation: when running under debug and manually looping, Excel instances appear but, at certain point, they disappeared (say, when reaching 7 and triggering the 8th, only one was left).
– FDavidov
Oct 22 '17 at 4:26