Killing a process
-
Did you try something along the lines of Where _excelApplication = Excel.Application
_excelApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApplication);?
Just did both quit and ReleaseComObject methods but still there.
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
-
Just did both quit and ReleaseComObject methods but still there.
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
-
Without seeing your code I'd say your out of luck.
Hope you can follow it through since I have written it in VB.NET. This is just a wrapper. The parts which might be of interest to you are the constructor and the Create method. Public Class ExcelBook Implements IObservable Private _parameters As Parameters Private _repoHelper As RepositoryHelper Private _sheets As Dictionary(Of String, Worksheet) Private _workBook As Workbook Private _xlApp As Application Private _summarySheet As ExcelSheet Public Sub New(ByVal params As Parameters) Me._xlApp = New Application() Me._workBook = Me._xlApp.Workbooks.Add() Me._repoHelper = Nothing Me._sheets = New Dictionary(Of String, Worksheet)(53) Me._parameters = params End Sub Private Sub DeleteDefaultSheets() Dim DeadSheet As Worksheet DeadSheet = Me._workBook.Sheets("Sheet1") DeadSheet.Delete() DeadSheet = Me._workBook.Sheets("Sheet2") DeadSheet.Delete() DeadSheet = Me._workBook.Sheets("Sheet3") DeadSheet.Delete() End Sub Public Sub Create() Me.CreateRepositories() Dim xSheet As ExcelSheet = Nothing Dim sheetSpecs As Sheet = Nothing Dim wSheet As Worksheet = Nothing ' If the report has a detail sheet and range is multiple for month or week or season then provide detail sheet specs to ' ExcelSheet constructor to create sheets with specification of the detail sheet ' First sheet must be reserved for the summary sheet ' After all detail sheets are finished, a summary sheet must be created. Dim stepInfo As New StepEventArgs() If (Me._parameters.Report.HasDetailSheet And Me._parameters.IsMultipleRanges) Then ' Details Sheets sheetSpecs = Me._parameters.Report.DetailSheet For Each repo As KeyValuePair(Of String, Repository) In Me._repoHelper wSheet = CType(Me._workBook.Worksheets.Add(), Worksheet) wSheet.Name = repo.Key xSheet = New ExcelSheet(wSheet, sheetSpecs, repo.Value, False, Me._parameters, Me._workBook) xSheet.Fill() Me._sheets.Add(repo.Key, xSheet.SpreadSheet) stepInfo.Message = repo.Key & " completed." RaiseEvent StepCompleted(Me, stepInfo) Next Me.DeleteDefaultSheets() ' All detail sheets are done now do the summary Dim repositoryTem
-
Hope you can follow it through since I have written it in VB.NET. This is just a wrapper. The parts which might be of interest to you are the constructor and the Create method. Public Class ExcelBook Implements IObservable Private _parameters As Parameters Private _repoHelper As RepositoryHelper Private _sheets As Dictionary(Of String, Worksheet) Private _workBook As Workbook Private _xlApp As Application Private _summarySheet As ExcelSheet Public Sub New(ByVal params As Parameters) Me._xlApp = New Application() Me._workBook = Me._xlApp.Workbooks.Add() Me._repoHelper = Nothing Me._sheets = New Dictionary(Of String, Worksheet)(53) Me._parameters = params End Sub Private Sub DeleteDefaultSheets() Dim DeadSheet As Worksheet DeadSheet = Me._workBook.Sheets("Sheet1") DeadSheet.Delete() DeadSheet = Me._workBook.Sheets("Sheet2") DeadSheet.Delete() DeadSheet = Me._workBook.Sheets("Sheet3") DeadSheet.Delete() End Sub Public Sub Create() Me.CreateRepositories() Dim xSheet As ExcelSheet = Nothing Dim sheetSpecs As Sheet = Nothing Dim wSheet As Worksheet = Nothing ' If the report has a detail sheet and range is multiple for month or week or season then provide detail sheet specs to ' ExcelSheet constructor to create sheets with specification of the detail sheet ' First sheet must be reserved for the summary sheet ' After all detail sheets are finished, a summary sheet must be created. Dim stepInfo As New StepEventArgs() If (Me._parameters.Report.HasDetailSheet And Me._parameters.IsMultipleRanges) Then ' Details Sheets sheetSpecs = Me._parameters.Report.DetailSheet For Each repo As KeyValuePair(Of String, Repository) In Me._repoHelper wSheet = CType(Me._workBook.Worksheets.Add(), Worksheet) wSheet.Name = repo.Key xSheet = New ExcelSheet(wSheet, sheetSpecs, repo.Value, False, Me._parameters, Me._workBook) xSheet.Fill() Me._sheets.Add(repo.Key, xSheet.SpreadSheet) stepInfo.Message = repo.Key & " completed." RaiseEvent StepCompleted(Me, stepInfo) Next Me.DeleteDefaultSheets() ' All detail sheets are done now do the summary Dim repositoryTem
next time, post your question in the vb.net forums, it really helps to know what language you are dealing with. Secondly, use the pre tags. Thirdly, this is how I did it (in vb.net)
Public Sub Terminate()
If _excelApplication IsNot Nothing Then
_excelApplication.DisplayAlerts = False
_excelApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApplication)
_excelApplication = Nothing
_excelApplication.Finalize()
End If
End Subjeez.
-
next time, post your question in the vb.net forums, it really helps to know what language you are dealing with. Secondly, use the pre tags. Thirdly, this is how I did it (in vb.net)
Public Sub Terminate()
If _excelApplication IsNot Nothing Then
_excelApplication.DisplayAlerts = False
_excelApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(_excelApplication)
_excelApplication = Nothing
_excelApplication.Finalize()
End If
End Subjeez.
Sorry about that. The reason I posted it here is because I did not think it will get to the point where I need to post code. Still no luck. The process exists after doing all of the above.
EliottA wrote:
Thirdly, this is how I did it (in vb.net)
You mean it worked for you? Finalize() is not a member of Excel.Application.
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
-
Sorry about that. The reason I posted it here is because I did not think it will get to the point where I need to post code. Still no luck. The process exists after doing all of the above.
EliottA wrote:
Thirdly, this is how I did it (in vb.net)
You mean it worked for you? Finalize() is not a member of Excel.Application.
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
Sorry, did not mean to throw that line in there.
CodingYoshi wrote:
he reason I posted it here is because I did not think it will get to the point where I need to post code.
Still belongs in the VB.Net forum.
CodingYoshi wrote:
The process exists after doing all of the above.
Err....ummm....does the process exist
before
execution...? -
Sorry, did not mean to throw that line in there.
CodingYoshi wrote:
he reason I posted it here is because I did not think it will get to the point where I need to post code.
Still belongs in the VB.Net forum.
CodingYoshi wrote:
The process exists after doing all of the above.
Err....ummm....does the process exist
before
execution...?No, I manually check to make sure no process exists before the execution and I also kill all the instances programmatically just to reassure using this code: foreach (Process p in Process.GetProcessesByName("EXCEL")) { p.Kill(); }
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
-
No, I manually check to make sure no process exists before the execution and I also kill all the instances programmatically just to reassure using this code: foreach (Process p in Process.GetProcessesByName("EXCEL")) { p.Kill(); }
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
Again that is horrible design, what if a client has excel running? Create a new instance of excel, and set it's IgnoreRemoteRequests property to true, this will cause *your* instance of excel to operate under a new process.
-
I wrote an app which creates excel reports. I would like to kill all the excel processes my application started. How do I figure out if my application started the process so I only kill those processes? I have this code so far: foreach (Process p in Process.GetProcessesByName("EXCEL")) { p.Kill(); } However, as it is clear from the code, it kills all excel processes.
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
How do you create excell processes? System.Diagnostics.Process.Start("...") Something like that? If so save the process that you create.
List list = new List();
Process p = System.Diagnostics.Process.Start("...");
list.Add(p);
...
list[i].Kill();:)
-
How do you create excell processes? System.Diagnostics.Process.Start("...") Something like that? If so save the process that you create.
List list = new List();
Process p = System.Diagnostics.Process.Start("...");
list.Add(p);
...
list[i].Kill();:)
No, the problem is to make excel spreadsheets you have to create a new instance of the application class and add workbooks to it. This creates a process and I am trying to kill the process which I created but no luck so far. Here is the snippet: public void Constructor(Parameters params) { this._xlApp = New Application(); // This is the process I want to kill once I am finished creating the file. this._workBook = Me._xlApp.Workbooks.Add(); this._repoHelper = null; this._sheets = New Dictionary<String, Worksheet>(53); this._parameters = params; }
CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07