簡體   English   中英

后台工人德爾福

[英]Background Worker Delphi

我想為Delphi Borland 2006中的過程准備異步過程,您知道如何嗎?

application.ProcessMessages;
  dm001.Proc.Close;
  dm001.Proc.Parameters.Clear;
  dm001.Proc.ProcedureName:='[dbo].[EXAMPLE]';
  dm001.Proc.Parameters.AddParameter.Name:='@idEXAMPLE';
  dm001.Proc.Parameters.ParamByName('@id').DataType:="example";
  dm001.Proc.Parameters.ParamByName('@id').Value:="example";
  dm001.Proc.Open;

C#中的示例

private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundWorker worker = sender as BackgroundWorker;

    for (int i = 1; (i <= 10); i++)
    {
        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            break;
        }
        else
        {
            // Perform a time consuming operation and report progress.
            System.Threading.Thread.Sleep(500);
            worker.ReportProgress((i * 10));
        }
    }
}

要么

private void buttonStart_Click(object sender, RoutedEventArgs e)
{
    if (bw.IsBusy != true)
    {
        bw.RunWorkerAsync();
    }
}

BackgroundWorker僅僅是一個線程實現。 但是有一個組件可以在Delphi上模擬此行為,例如TBackgroundWorker

使用TADOQuery測試“選擇”請求。

1)將“ ExecuteOptions”,“ eoAsyncExecute”和“ asAsyncFetch”更改為True

2)使用事件“ OnFetchProgress”進行確定,是否完成了異步請求。 如果“ Progress” =“ MaxProgress”,則異步請求已完成。

經過Delphi 2007和2009測試。

您可以嘗試一個受人尊敬的AsyncCalls單元。 Delphi 2009發布后,它並沒有得到更多的開發,但是您還是不要使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM