|
|
Hi,
I downloaded the sample autoupdater application from
http://msdn.microsoft.com/msdnmag/issues/03/02/BITS/default.aspx
I am running WINDOWS XP SP1 with BITS service successfully running under
local system account.
When I run this application, it throws me BG_JOB_STATE_ERROR when I check
the state of the job. the statement " job.GetState(out state);"
returns BG_JOB_STATE_ERROR ALWAYS. I am not sure if job is getting added or
not.
I have kept the files under localhost/updates">http://localhost/updates with ONLY anonymous
access on.
Can somebody help me out.
Here is the code snippit
// Do the file download and polling logic
static void HandleBits(Object o){
IBackgroundCopyManager bcm = null;
IBackgroundCopyJob job=null;
try{
// Create BITS object
bcm = (IBackgroundCopyManager)new BackgroundCopyManager();
Guid jobID=Guid.Empty;
if(xml.BitsJob != Guid.Empty){ // Do we already have a job in place?
jobID = xml.BitsJob;
BG_JOB_STATE state;
try{
bcm.GetJob(ref jobID, out job); // Get the BITS job object
job.GetState(out state); // check its state
switch(state){
case BG_JOB_STATE.BG_JOB_STATE_ERROR: // If it is an error,
re-poll
job.Complete();
xml.BitsJob = Guid.Empty;
Marshal.ReleaseComObject(job);
job = null;
break;
case BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED: // If we got the
job
job.Complete(); // then complete it
xml.BitsJob = Guid.Empty;
return;
default:
return;
}
}catch(COMException e){
if(e.ErrorCode == unchecked((Int32)0x80200001)){ // Job
doesn't exist
xml.BitsJob = Guid.Empty;
}else
throw; // Some other error we didn't expect
}catch(UnauthorizedAccessException){
return; // We don't have access to the current job... no biggie
}
}
// Create a bits job to download the next expected update
bcm.CreateJob("Application Update",
BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out jobID, out job);
job.SetDescription("Updating application at "+baseDir);
String resource;
if(xml.PatchUrl[xml.PatchUrl.Length-1] == '/'){
resource = xml.PatchUrl+patchName;
}else{
resource =
String.Format("{0}/{1}", xml.PatchUrl, patchName);
}
// Add the file to the job
job.AddFile(resource, baseDir+patchName);
job.Resume(); // start the job in action
xml.BitsJob = jobID; // save the Job Guid
}finally{
// cleanup
if(job != null)
Marshal.ReleaseComObject(job);
if(bcm != null)
Marshal.ReleaseComObject(bcm);
}
}
|
|