Bagikan melalui


Menentukan Kemajuan Pekerjaan

BITS mempertahankan informasi kemajuan untuk setiap pekerjaan. Gunakan informasi kemajuan untuk menentukan berapa banyak byte dan file yang telah ditransfer.

Untuk mengambil informasi kemajuan untuk pekerjaan, panggil metode IBackgroundCopyJob::GetProgress seperti yang ditunjukkan dalam contoh berikut. Contoh mengasumsikan penunjuk antarmuka IBackgroundCopyJob valid.

#define PROGRESS_COMPLETE_LEN 50

HRESULT hr;
IBackgroundCopyJob* pJob;
WCHAR szProgressComplete[PROGRESS_COMPLETE_LEN+1];
BG_JOB_PROGRESS Progress;

hr = pJob->GetProgress(&Progress); 
if (FAILED(hr))
{
  //Handle error
}

//Because the BytesTotal member can be 0 or BG_SIZE_UNKNOWN, you may not be able 
//to determine a percentage value to display, such as 57%. It is best to display a 
//string that shows the number of bytes transferred. For example, "123456 of 
//999999" or "123456 of Unknown".
if (BG_SIZE_UNKNOWN == Progress.BytesTotal)
{
  StringCchPrintf(szProgressComplete, PROGRESS_COMPLETE_LEN+1, L"%I64d of Unknown", 
     Progress.BytesTransferred);
}
else
{
  StringCchPrintf(szProgressComplete, PROGRESS_COMPLETE_LEN+1, L"%I64d of %I64d", 
     Progress.BytesTransferred, Progress.BytesTotal); 
}

Untuk mengambil informasi kemajuan tentang bagian balasan dari pekerjaan balasan unggahan, panggil metode IBackgroundCopyJob2::GetReplyProgress seperti yang ditunjukkan dalam contoh berikut. Contoh mengasumsikan penunjuk antarmuka IBackgroundCopyJob valid.

#define REPLY_COMPLETE_LEN 4

HRESULT hr;
IBackgroundCopyJob* pJob;
IBackgroundCopyJob2* pJob2 = NULL;
WCHAR szReplyComplete[REPLY_COMPLETE_LEN+1];
BG_JOB_REPLY_PROGRESS Progress;

pJob->QueryInterface(__uuidof(IBackgroundCopyJob2), (void**)&pJob2);
hr = pJob2->GetReplyProgress(&Progress); 
if (SUCCEEDED(hr))
{
  if (0 == Progress.BytesTotal) //The job type is not BG_JOB_TYPE_UPLOAD_REPLY
  {
    //Logic to deal with this case  
  }
  else if (BG_SIZE_UNKNOWN == Progress.BytesTotal) //The reply has not begun
  {
    StringCchPrintf(szReplyComplete, REPLY_COMPLETE_LEN+1, L"0%%");
  }
  else
  {
    StringCchPrintf(szReplyComplete, REPLY_COMPLETE_LEN+1 L"%I64d%%",
       100*Progress.BytesTransferred/Progress.BytesTotal); 
  }
}

File juga berisi informasi kemajuan. Untuk mengambil informasi kemajuan, gunakan metode IBackgroundCopyFile::GetProgress. Untuk informasi tentang cara mengambil file pekerjaan, lihat Menghitung File dalam Pekerjaan.