如何在长时间运行的方法中返回AsyncResult

时间:2014-08-29 06:54:22

标签: c#

我有一个方法可以创建一个随机大小的文件,并希望输出正在创建的文件进度的状态进度。以下是使用的方法:

   public IAsyncResult CreateRandomFile(string destPath, int bytesUsed)
    {

        byte[] dataArray = new byte[bytesUsed];
        new Random().NextBytes(dataArray);


            using (FileStream destStream = new FileStream(destPath, FileMode.Create))
            {
                for (int i = 0; i < dataArray.Length; i++)
                {
                    destStream.WriteByte(dataArray[i]);


                    /// I am not sure how to return or use IAsyncResult such that
                    /// I will be able to access the status of how many bytes have 
                    /// been copied

                    IAsyncResult++;
                }
            }



        return ias;
    }

如何正确退回IASyncResult

0 个答案:

没有答案