Stop form from Closing

In my application, When I click the submit button on the MainForm, the Please Wait form appears, which shows untill the processing is complete. The submit button redirects to Books.cs. When someone accidentally clicks the Close(X) sign on the main form(MainForm.cs), the form is closed but the execution is not terminated, the please wait form continues to show and completes the process. It is because the processing is done on a different thread. I want to prevent the user from closing the MainForm when the processing is in progress.
My issue is that e.Cancel does not seem to be working. I can still close the mainform. I tried to set the breakpoint on the mainform form closing event, but that breakpoint never hit.

MainForm.cs

private bool isProcessing = false;

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (isProcessing)
    {
        e.Cancel = true; // Cancel the closing event
    }
    else
    { 
     e.Cancel = false;

    }

public void SetProcessingState(bool processing)
{
    isProcessing = processing;
}

Books.cs


private async Task btnClick()
{
    MainForm mainform = new MainForm();
    
try
    {
      mainForm.SetProcessingState(true);

        cts = new CancellationTokenSource();

        PleaseWait pleasewait = new PleaseWait();
        pleasewait.Closed += PleaseWait_Closed;
 
        pleasewait.Show();

try{
        // Perform your long-running task asynchronously
        await Task.Run(() => ProcessBookstoreExcel(cts.Token));
}
catch(OperationCanceledException)
{
       cancel = true;
        pleasewait.Close();
       //showmessage
}
catch(Exception ex)
{
        pleasewait.Close();
       //showmessage
}
        pleasewait.Closed -= PleaseWait_Closed;

        pleasewait.Close();

        if(!cancel)
        MessageBox.Show("Processing Complete!");
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        cts.Dispose();

        cts = null;
        mainForm.SetProcessingState(false);

    }
}

private void PleaseWait_Closed(object sender, EventArgs e) => cts.Cancel();

private void ProcessBookstoreExcel(CancellationToken cancellationToken)
{

try{

    string path = TxtBox.Text;
    ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
    var records = new List<BookRecord>();

    using (var package = new ExcelPackage(new FileInfo(path)))
    {
        ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
        int rowCount = worksheet.Dimension.Rows;

        for (int row = 2; row <= rowCount; row++) // Skip header row
        {
            cancellationToken.ThrowIfCancellation();

            records.Add(new BookRecord
            {
                LineNumber = row,
                ISBN = worksheet.Cells[row, 1].Text,
                Title = worksheet.Cells[row, 2].Text,
                Stock = int.Parse(worksheet.Cells[row, 3].Text),
                Price = decimal.Parse(worksheet.Cells[row, 4].Text),
                PublisherID = int.Parse(worksheet.Cells[row, 5].Text),
                PublisherName = worksheet.Cells[row, 6].Text
            });
        }
    }

    var discrepancies = new List<Discrepancy>();
    var groupedRecords = new Dictionary<string, Dictionary<string, (decimal Price, int Stock)>>();

    foreach (var record in records)
    {
        cancellationToken.ThrowIfCancellation();
 
        var publisherKey = record.PublisherID.ToString();
        var isbnKey = record.ISBN;

        if (!groupedRecords.ContainsKey(publisherKey))
        {
            groupedRecords[publisherKey] = new Dictionary<string, (decimal Price, int Stock)>();
        }

        if (!groupedRecords[publisherKey].ContainsKey(isbnKey))
        {
            groupedRecords[publisherKey][isbnKey] = (record.Price, record.Stock);
        }
        else
        {
            var existing = groupedRecords[publisherKey][isbnKey];
            if (existing.Price != record.Price || existing.Stock != record.Stock)
            {
                discrepancies.Add(new Discrepancy
                {
                    LineNumber = record.LineNumber,
                    Publisher = record.PublisherName,
                    Title = record.Title
                });
            }
        }
    }

    WriteDiscrepancies(discrepancies);
}
catch(OperationCanceledException)
{
throw;
}
catch(Exception ex)
{
throw;
}
}

private void WriteDiscrepancies(List<Discrepancy> discrepancies)
{
    try{
    var outputPath = Path.Combine(Path.GetDirectoryName(filePath), "discrepancies.xlsx");

    using (var package = new ExcelPackage())
    {
        var worksheet = package.Workbook.Worksheets.Add("Discrepancies");
        worksheet.Cells[1, 1].Value = "LineNumber";
        worksheet.Cells[1, 2].Value = "Publisher";
        worksheet.Cells[1, 3].Value = "Title";

        for (int i = 0; i < discrepancies.Count; i++)
        {
            worksheet.Cells[i + 2, 1].Value = discrepancies[i].LineNumber;
            worksheet.Cells[i + 2, 2].Value = discrepancies[i].Publisher;
            worksheet.Cells[i + 2, 3].Value = discrepancies[i].Title;
        }

        package.SaveAs(new FileInfo(outputPath));
    }
    }
    catch
    {
        throw;
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật