How to have the cancel button enabled during an upload process

Discussion in 'C#' started by Leo, Nov 14, 2006.

  1. Leo

    Leo New Member

    Joined:
    Nov 10, 2006
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    Actually my aim to enable a cancel button while this upload takes place.I tried raising an event which makes the cancel button enabled while the upload process is going on.

    But I am not able to click on the cancel button, i dont get the access to click it.Once the process is completed i am able to click the button to generate the event.

    Does any one know how this can be done in C#(Windows application)

    Sample code is :
    Code:
    while (bytesRead > 0) 
    { 
    
    if (iteration == 1) 
    this._startTime = DateTime.Now; 
    
    bytesWritten = this._workFlowProxy.UploadChunk(this._taskId, buffer, sentBytes, bytesRead); 
    if (iteration == LoadManagerConstants.AverageSample + 1) //AverageSample = 5 
    { 
    timeForInitialChunks = (long)DateTime.Now.Subtract(this._startTime).TotalMilliseconds; 
    averageChunkTime = System.Math.Max 
    (1, timeForInitialChunks / LoadManagerConstants.AverageSample); 
    
    //Maximum size that can be uploaded at a time cannot be more than 4KB 
    chunkSize = (int)System.Math.Min(LoadManagerConstants.MaxFileSize, 
    chunkSize * preferredTransferDuration / averageChunkTime); 
    
    buffer = new byte[chunkSize]; 
    } 
    sentBytes += bytesRead; 
    percentageOfTotalSize = (int)(((decimal)sentBytes / (decimal)fileSize) * 100); 
    this.SetProgressStatus(percentageOfTotalSize); 
    bytesRead = fileToUpLoad.Read(buffer, LoadManagerConstants.Offset, chunkSize); 
    iteration++; 
    }
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Refer to thread [thread=1885] How to enable a cancel button when an upload takes place[/thread].
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice