Application hangs when executing WaitForPendingFinalizers

Nino Triono 1 Reputation point
2022-02-04T04:53:15.517+00:00

I am troubleshooting a bug in a GUI application build on VS2008 using .net 3.5

The application hangs when executing GC::WaitForPendingFinalizers().

But the application does not hang every time it executes GC::WaitForPendingFinalizers().
The application hangs only after it goes through a path to interact with user using a customised messageBox.

I tried replacing the customised messageBox with default MessageBox.Show(text, caption, buttons);
The app does not hang using the default MessageBox.

Could anyone help on how to deal with this please?

This is the code calling the customised messageBox

if(!bPrintQualityOk)
{`enter code here`
    try
    {
        Logger->Trace(String::Format("Low Print Quality : slap {0}, description {1}, capture status {2}", m_CaptureSlap->Slap.ToString(), m_CaptureSlap->Description, m_CaptureSlap->CaptureStatus.ToString() ));

        qualityCheckFailed = gcnew QualityCheckFailed();                                                            
        System::Windows::Forms::DialogResult dlgresult = qualityCheckFailed->ShowDialog();
        delete qualityCheckFailed;

Here is the code for customised messageBox:

namespace XXXX {

    /// <summary>
    /// Summary for QualityCheckFailed
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    ///          'Resource File Name' property for the managed resource compiler tool
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>

    public ref class QualityCheckFailed : System::Windows::Forms::Form
    {
    public:

        QualityCheckFailed(void)
        {
            InitializeComponent();

            m_autoCloseTimer = gcnew System::Windows::Forms::Timer();
            m_autoCloseTimer->Interval = 5000 * 6; 
            m_autoCloseTimer->Tick += gcnew System::EventHandler(this, &QualityCheckFailed::autoCloseTimer_Tick);

        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~QualityCheckFailed()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  cmdIgnore;
    protected: 
    private: System::Windows::Forms::Button^  cmdRetry;

    private: System::Windows::Forms::Button^  cmdAbort;
    private: System::Windows::Forms::Label^  lblError;


    void autoCloseTimer_Tick( Object^ sender, EventArgs^ e ) 
    { 
        DialogResult = System::Windows::Forms::DialogResult::Retry;
        Close();

    }
    private: System::ComponentModel::IContainer^  components;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>

        bool m_AltF4Pressed;
        System::Windows::Forms::Timer^ m_autoCloseTimer;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->cmdIgnore = (gcnew System::Windows::Forms::Button());
            this->cmdRetry = (gcnew System::Windows::Forms::Button());
            this->cmdAbort = (gcnew System::Windows::Forms::Button());
            this->lblError = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // cmdIgnore
            // 
            this->cmdIgnore->DialogResult = System::Windows::Forms::DialogResult::Ignore;
            this->cmdIgnore->Location = System::Drawing::Point(153, 56);
            this->cmdIgnore->Name = L"cmdIgnore";
            this->cmdIgnore->Size = System::Drawing::Size(75, 23);
            this->cmdIgnore->TabIndex = 2;
            this->cmdIgnore->Text = L"Accept";
            this->cmdIgnore->UseVisualStyleBackColor = true;
            this->cmdIgnore->Click += gcnew System::EventHandler(this, &QualityCheckFailed::cmdIgnore_Click);
            // 
            // cmdRetry
            // 
            this->cmdRetry->DialogResult = System::Windows::Forms::DialogResult::Retry;
            this->cmdRetry->Location = System::Drawing::Point(61, 56);
            this->cmdRetry->Name = L"cmdRetry";
            this->cmdRetry->Size = System::Drawing::Size(75, 23);
            this->cmdRetry->TabIndex = 1;
            this->cmdRetry->Text = L"Retry";
            this->cmdRetry->UseVisualStyleBackColor = true;
            this->cmdRetry->Click += gcnew System::EventHandler(this, &QualityCheckFailed::cmdRetry_Click);
            // 
            // cmdAbort
            // 
            this->cmdAbort->DialogResult = System::Windows::Forms::DialogResult::Abort;
            this->cmdAbort->Location = System::Drawing::Point(27, 92);
            this->cmdAbort->Name = L"cmdAbort";
            this->cmdAbort->Size = System::Drawing::Size(75, 23);
            this->cmdAbort->TabIndex = 2;
            this->cmdAbort->Text = L"Abort";
            this->cmdAbort->UseVisualStyleBackColor = true;
            this->cmdAbort->Visible = false;
            this->cmdAbort->Click += gcnew System::EventHandler(this, &QualityCheckFailed::cmdAbort_Click);
            // 
            // lblError
            // 
            this->lblError->Location = System::Drawing::Point(49, 9);
            this->lblError->Name = L"lblError";
            this->lblError->Size = System::Drawing::Size(199, 44);
            this->lblError->TabIndex = 3;
            this->lblError->Text = L"Quality Check for prints Failed!";
            // 
            // QualityCheckFailed
            // 
            this->AcceptButton = this->cmdRetry;
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(287, 100);
            this->Controls->Add(this->lblError);
            this->Controls->Add(this->cmdAbort);
            this->Controls->Add(this->cmdRetry);
            this->Controls->Add(this->cmdIgnore);
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
            this->KeyPreview = true;
            this->MaximizeBox = false;
            this->MinimizeBox = false;
            this->Name = L"QualityCheckFailed";
            this->ShowInTaskbar = false;
            this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
            this->TopMost = true;
            this->Load += gcnew System::EventHandler(this, &QualityCheckFailed::QualityCheckFailed_Load);
            this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &QualityCheckFailed::QualityCheckFailed_FormClosing);
            this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &QualityCheckFailed::QualityCheckFailed_KeyDown);
            this->ResumeLayout(false);

        }
#pragma endregion

private: System::Void QualityCheckFailed_Load(System::Object^  sender, System::EventArgs^  e) {

             cmdRetry->Focus();

             this->BringToFront();
             m_autoCloseTimer->Start();
         }
private: System::Void cmdAbort_Click(System::Object^  sender, System::EventArgs^  e) {
             Logger->Trace("QualityCheckFailed - ABORT selected");
             Close();
         }
private: System::Void cmdRetry_Click(System::Object^  sender, System::EventArgs^  e) {
             Logger->Trace("QualityCheckFailed - RETRY selected");
             Close();
         }
private: System::Void cmdIgnore_Click(System::Object^  sender, System::EventArgs^  e) {
             Logger->Trace("QualityCheckFailed - IGNORE selected");
             Close();
         }
private: System::Void QualityCheckFailed_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {

             if (m_AltF4Pressed)
            {
                if (e->CloseReason == System::Windows::Forms::CloseReason::UserClosing)
                    e->Cancel = true;

                m_AltF4Pressed = false;

            }
             else
             {
                Logger->Trace("QualityCheckFailed - FormClosing - stop timer");
                m_autoCloseTimer->Stop();
                delete m_autoCloseTimer;
                Logger->Trace("QualityCheckFailed - FormClosing - timer deleted");
            }
         }
private: System::Void QualityCheckFailed_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
            if (e->Alt && e->KeyCode == Keys::F4)
             {
                e->SuppressKeyPress = true;
                m_AltF4Pressed = true;              
             }
         }
};
}
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
325 questions
0 comments No comments
{count} votes