0

Is there any way that I can continue to the next function below (within the same function class) without closing the current m_frmLotEntry?

void ShowLotEntry()
    {            
        DialogResult _dlgRet = DialogResult.None;
        _dlgRet = m_frmLotEntry.ShowDialog(this);
        
        // Next function here
    }

Updates : I managed to proceed with the code by changing the codes to below.

void ShowLotEntry()
    {            
        DialogResult _dlgRet = DialogResult.None;
        BeginInvoke(new System.Action(() => m_frmLotEntry.ShowDialog()));
        
        // Next function here
    }

The programs now proceed with the next step. However, I have another issue which is the next next function requires some data from the users key-in in the previous windows form. Therefore, is there any possible way that I can do to stop halfway through the next process?

  void ShowLotEntry()
    {            
        DialogResult _dlgRet = DialogResult.None;
        BeginInvoke(new System.Action(() => m_frmLotEntry.ShowDialog()));

        // Proceed with this function here.

        // Stop before the function below.
        if (_dlgRet == DialogResult.OK)
        {
            // Some codes here

        }

Thanks.

  • What have you tried so far? Where is `m_frmLotEntry` defined? You can call `m_frmLotEntry.Show()` instead of `m_frmLotEntry.ShowDialog()`. – Sebastian Siemens Jan 06 '22 at 08:16
  • Have you tried calling `.Show()` instead of `.ShowDialog()` ? – Lasse V. Karlsen Jan 06 '22 at 08:23
  • Does this answer your question? [Async ShowDialog](https://stackoverflow.com/questions/33406939/async-showdialog) – Sandeep Jadhav Jan 06 '22 at 08:45
  • The BeginInvoke() function works perfectly. However, some codes below requires data to be entered and only run after user closes the windows form. I have updated my questions. –  Jan 06 '22 at 09:02
  • Use an event to signal that some relevant data has been entered. – Hans Passant Jan 06 '22 at 09:57
  • @HansPassant can you give example on this event method? To clarify, all data need to be entered first before the program can proceed for the next code. –  Jan 06 '22 at 10:19

1 Answers1

0

ShowDialog is blocking operation and waits the return. You can start thread/task before showing the dialog and that would run "behind the scene" even though that the dialog is open. What about Show() would that be enough?

Check this answer for more details: Async ShowDialog

Panu Oksala
  • 3,245
  • 1
  • 18
  • 28