Close Bartend フォローする

0
Avatar
Legacy Poster

Quick one,

I'm currently using bartender via C# to loop through an array of bartender files but I've noticed that bartend.exe will stay open in the task mannager. Am I not correctly closing bartender via "btApp.Quit"

Bartender Enterprise 9.4

Thanks for the help,
James


//Launch bartender files                 
string excPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
              
BarTender.ApplicationClass btApp;                
BarTender.Format btFormat;                
BarTender.Messages btMsgs;                

//Loop through array of all the files.                

foreach (string for_string in string_array_bt)      
 {                    
string temp_path = excPath + "\\" + str_FileNames + "\\" + for_string+".btw";                    
btApp = new BarTender.ApplicationClass();                    
btFormat = btApp.Formats.Open(temp_path, false, "");                    

//Pulls Data from DataGridView                    
btFormat.Print(temp_path, false, 1, out btMsgs);                    
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);                    
Debug.WriteLine(temp_path);                    

MessageBox.Show("Sent Job " + for_string + " to printer";

 }

2 コメント

0
Avatar
Legacy Poster
コメントアクション Permalink

Hum I've done this in version 10.4 but based on what I read it should be working in 9.4.

First you should take out of your loop the creating of your BarTender.ApplicationClass.

Then you can close it only when the loop is done.

 

In your loop you should create and destroy your btFormat. So your code should look like this :

 

//Launch bartender files
string excPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

BarTender.ApplicationClass btApp;
BarTender.Format btFormat;
BarTender.Messages btMsgs;

 

btApp = new BarTender.ApplicationClass();

//Loop through array of all the files.

foreach (string for_string in string_array_bt)
{
string temp_path = excPath + "\\" + str_FileNames + "\\" + for_string+".btw";
btFormat = btApp.Formats.Open(temp_path, false, "");

//Pulls Data from DataGridView
btFormat.Print(temp_path, false, 1, out btMsgs);
btFormat.Close();
Debug.WriteLine(temp_path);

MessageBox.Show("Sent Job " + for_string + " to printer";

}

 

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges); 

1
Avatar
Ian Cummings
モデレータ
コメントアクション Permalink

It should be noted that .NET can hold on to the BarTender object even after the Quit() method has been called.  To force .NET to release the object, make the following call:
 
System.Runtime.InteropServices.Marshal.ReleaseComObject(btApp)
 
Make the call after calling Quit and before you set the BarTender instance object to Nothing.  Check the Windows task manager to see if the "bartend.exe" process is removed and that memory is released to the system.

ログインしてコメントを残してください。