How to cancel a transfer that is in progress?

Jun 7, 2008 at 4:15 AM
I might be overlooking the simple, but how do you cancel an upload or download that is in progress?

I've got multiple files in progress at a time. It is rare, but it does happen. I need to cancel the transfer. I typically just have small files and never really noticed that the upload continued until the current file was in progress. I was uploading a large file ~ 20 MB, hit cancel and it continued to progress until that file was finished and then it canceled as expected.

Looking back I guess it makes sense that you can't remove the current.

Jun 7, 2008 at 4:53 AM
I was looking for a simple solution. Someone comment on what I did.

I needed a way to cancel all current and pending transfers uploads or downloads. Here's what I did. It works, but I want feedback if anyone is willing as to how to make this better.

In ThreeShartQuery.cs I added this

        bool allowTransfer = true;
        public void CancelTransfers()
            allowTransfer = false;
            foreach( Transfer tnfr in this.statistics.GetTransfers() )

and modified the GenerateAndSendHttpWebRequest method by changing this line:
    while (true)
    while (allowTransfer)

I also added this to Transfer.cs

    protected bool allowTransfer = true;
        public void Cancel()
            allowTransfer = false;

and modified the TransferStream method of Response.cs by changing the while loop test to
    while( allowTransfer )

This seems to work in my current tests, but I just can't see it being the cleanest solution. I look forward to any feedback.

Especially if I'm just stupid and can't find the right way to do it that already exists.