Improvement suggestion: Avoid NullReferenceException in Cancel, Abort, Suspend and Resume if invoking a method on a job that was canceled or completed

Dec 16, 2012 at 3:18 PM

Before I explain my suggestion: Thanks for the great work with SharpBITS. It works really well. I am currently examining SharpBITS very closely because I explain it as the BITS solution in my C# Codebook 2012. I did not find any major error so far and it works really smooth.

My suggestion would be to improve the methods Cancel, Abort, Suspend and Resume. They throw a NullReferenceException if the job was canceled or aborted in the meantime. I and others treat NullReferenceExceptions usually as fatal exceptions and would not catch it. But in case of Cancel, Abort, Suspend and Resume I have to catch it (I know: I can check the State if it is Canceled, but checking the state does not work for completed jobs).

I would internally check if the BITS job does no longer exist and throw a dedicated exception (JobRemovedException or something).