public static void CPWork(object sender, DoWorkEventArgs e) { try { try { BasicFunctions.PlayConversionStart(); // First of all, initialize BASS itself BASSControl.BASSInitSystem(false); BASSControl.InitializeDummyVSTs(); foreach (String str in MainWindow.KMCGlobals.MIDIs) { // Initialize BASS stream BASSControl.BASSStreamSystem(str, false); BASSControl.BASSLoadSoundFonts(str); BASSControl.BASSInitVSTiIfNeeded(false); BASSControl.InitializeVSTsForStream(); BASSControl.BASSEffectSettings(); BASSControl.BASSVolumeSlideInit(); BASSControl.BASSEncoderInit(MainWindow.KMCGlobals.CurrentEncoder, str); // Get length of the stream Int64 pos = Bass.BASS_ChannelGetLength(MainWindow.KMCGlobals._recHandle); Int64 length = Convert.ToInt64(Bass.BASS_ChannelSeconds2Bytes(MainWindow.KMCGlobals._recHandle, 0.0275)); // KMC is now busy MainWindow.KMCStatus.IsKMCNowExporting = true; while (BASSControl.BASSEncodingEngine(pos, length)) { if (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) { break; } } BASSControl.ReleaseResources( (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER), (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ); if (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) { break; } } MainWindow.KMCStatus.RenderingMode = false; MainWindow.KMCStatus.IsKMCBusy = false; MainWindow.KMCStatus.IsKMCNowExporting = false; MainWindow.KMCGlobals.VSTSkipSettings = false; String Msg = (MainWindow.KMCGlobals.CancellationPendingValue == MainWindow.KMCConstants.CANCELLED_BY_USER) ? "ConversionAborted" : "ConversionCompleted"; BASSControl.BASSCloseStream(Languages.Parse(Msg), Languages.Parse(Msg), 0); if (MainWindow.KMCGlobals.CancellationPendingValue != MainWindow.KMCConstants.CANCELLED_BY_USER) { if (MainWindow.KMCGlobals.AutoShutDownEnabled == true) { Process.Start(new ProcessStartInfo("shutdown", "/s /t 0") { CreateNoWindow = true, UseShellExecute = false }); } if (MainWindow.KMCGlobals.AutoClearMIDIListEnabled) { MainWindow.Delegate.Invoke((MethodInvoker) delegate { MainWindow.Delegate.MIDIList.Items.Clear(); }); } } BasicFunctions.PlayConversionStop(); } catch (Exception exception) { BASSControl.BASSCloseStreamException(exception); } } catch (Exception exception2) { BASSControl.BASSCloseStreamException(exception2); } }