I am using Interop.cs to burn a CD/DVD. I use the Update event to show burn
progress. Everything works well the first time. From then onwards the Update
event is not fired.
I Burn is a separate thread. The thread method is shown below:
private static void RunBurnThread(object parameter)
{
try
{
BurnParameters burnParameters = parameter as BurnParameters;
pDiscImage = new MsftDiscFormat2Data();
pDiscImage.Recorder =
InitialiseRecorder(burnParameters.Device.CurrentDevice);
pDiscImage.ClientName = "Burning shoot";
IFileSystemImage fileSystemImage = new MsftFileSystemImage();
fileSystemImage.FreeMediaBlocks = pDiscImage.FreeSectorsOnMedia;
fileSystemImage.FileSystemsToCreate = (FsiFileSystems.FsiFileSystemISO9660
| FsiFileSystems.FsiFileSystemJoliet);
IFsiDirectoryItem directory = fileSystemImage.Root;
directory.AddTree(burnParameters.Directory, true);
IFileSystemImageResult image = fileSystemImage.CreateResultImage();
IStream stream = image.ImageStream;
DiscFormat2Data_Events burnProgress = pDiscImage as DiscFormat2Data_Events;
burnProgress.Update += new DiscFormat2Data_EventsHandler(OnBurnProgress);
try
{
pDiscImage.Write(stream);
burnProgress.Update -= new
DiscFormat2Data_EventsHandler(OnBurnProgress);
}
finally
{
if (pBurningDialog != null)
{
bool error = false;
bool close = true;
pBurningDialog.Invoke(new
UpdateBurnProgressMethod(pBurningDialog.UpdateProgress),
new object[] { 100, 100, BurnCompleteMessage, error,
close });
}
}
}
catch (Exception exp)
{
if (pBurningDialog != null)
{
string message = exp.ToString();
pBurningDialog.Invoke(
new UpdateBurnProgressMethod(pBurningDialog.UpdateProgress),
new object[] { -1, -1, message, true, false });