Background Worker Delphi

为君一笑 提交于 2019-12-31 06:59:27

问题


I would like to prepare asynchronous process for procedure in Delphi Borland 2006 do you know how?

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;

Example in 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));
        }
    }
}

or

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

回答1:


BackgroundWorker is not much more than a thread implementation. But there are a Components that emulate this behaviour on Delphi, such as TBackgroundWorker




回答2:


Tested with TADOQuery for "select" request.

1) Change "ExecuteOptions" "eoAsyncExecute" and "asAsyncFetch" to True

2) Use event "OnFetchProgress" for determinate, does async request was completed. If "Progress" = "MaxProgress" then async request completed.

Tested with Delphi 2007 and 2009.




回答3:


You may try a well-respected AsyncCalls unit. It is not more developed after Delphi 2009 was released, but you don't use it anyway.

  • http://www.tommesani.com/index.php/software/altapixshare/21.html
  • http://delphi.about.com/od/kbthread/a/delphi-thread-pool-example-using-asynccalls.htm


来源:https://stackoverflow.com/questions/21430812/background-worker-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!