0

DoWork()関数で、sipサーバーに登録します。それから私は返事を待たなければなりません。しかし、私が得た応答は別のイベントで受信されます。ただし、DoWork()でフラグを確認する前に、DoWork()はすべて完了し、応答が後に表示されます。

Diagnoticイベントで応答を受け取るまで、DoWork()で待機する方法を見つけようとしています。DoWork()でチェックする必要があるイベントで設定されるグローバルフラグがあります。

アドバイスありがとうございます、

// Do work in background worker
//Will return less than 8 if there are no error message from the library 
        if (!this.bgwProcessLogin.CancellationPending)
        {
                // Register and wait for response
                VaxSIPUserAgentOCX.RegisterToProxy(3600);
        }
        else
        {
                // Update label
                if (this.lblRegistering.InvokeRequired)
                {
                  // do something here
                }
                else
                {
                    // Display error
                }
         }

// WAIT FOR A RESPONSE FROM THE DIAGNOTIC EVENT BEFORE CONTINUING - MAYBE JOIN HERE
        if (!this.bgwProcessLogin.CancellationPending)
        {
            if (this.responseFlag)
            {
                // Do something here   
            }
            else
            {
                // Do something else here
            }
        }


// Another function where I receive the response
private void VaxSIPUserAgentOCX_OnIncomingDiagnostic(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingDiagnosticEvent e)
    {
        string messageSip = e.msgSIP;
        //Find this message in the sip header

        string sipErrorCode = "600 User Found"; 
        if (messageSip.Contains(sipErrorCode))
        {
            // Set global flag for response
            this.responseFlag = true;
        }
}
4

1 に答える 1

1

ManualResetEventを使用できます。コードが WaitOne 呼び出しに到達すると、イベントが設定されるまでブロックされます。WaitOne 呼び出しもオーバーロードされるため、必要に応じて待機時間を指定できます。

void SomeFunction()
{
// Do work in background worker
//Will return less than 8 if there are no error message from the library 
        if (!this.bgwProcessLogin.CancellationPending)
        {
                // Register and wait for response
                VaxSIPUserAgentOCX.RegisterToProxy(3600);
        }
        else
        {
                // Update label
                if (this.lblRegistering.InvokeRequired)
                {
                  // do something here
                }
                else
                {
                    // Display error
                }
         }

// WAIT FOR A RESPONSE FROM THE DIAGNOTIC EVENT BEFORE CONTINUING - MAYBE JOIN HERE

        waitEvent.WaitOne();
        if (!this.bgwProcessLogin.CancellationPending)
        {
            if (this.responseFlag)
            {
                // Do something here   
            }
            else
            {
                // Do something else here
            }
        }
}

ManualResetEvent waitEvent = new ManualResetEvent(false);

// Another function where I receive the response
private void VaxSIPUserAgentOCX_OnIncomingDiagnostic(object sender, AxVAXSIPUSERAGENTOCXLib._DVaxSIPUserAgentOCXEvents_OnIncomingDiagnosticEvent e)
    {
        string messageSip = e.msgSIP;
        //Find this message in the sip header

        string sipErrorCode = "600 User Found"; 
        if (messageSip.Contains(sipErrorCode))
        {
            // Set global flag for response
            this.responseFlag = true;
            waitEvent.Set();
        }
}
于 2009-05-06T14:41:57.720 に答える