コード例 #1
0
        protected PicDownloadEventArgs DownloadPic(PicItem url, string action)
        {
            WebRequest requestPic = WebRequest.Create(url.Url);
            WebResponse responsePic = requestPic.GetResponse();
            Stream stream = responsePic.GetResponseStream();
            FileStream outputStream = new FileStream(url.FilePath, FileMode.OpenOrCreate, FileAccess.Write);
            int cnt = 0;
            const int LEN = 4096;
            byte[] buffer = new byte[LEN];

            while ((cnt = stream.Read(buffer, 0, LEN)) != 0)
                outputStream.Write(buffer, 0, cnt);

            stream.Close();
            outputStream.Close();
            responsePic.Close();
            PicDownloadEventArgs args = new PicDownloadEventArgs();
            args.ImagePath = url.FilePath;
            args.item = url.Name;
            args.Action = action;
            return args;
        }
コード例 #2
0
 private void startDownloadPic(PicItem url, string action)
 {
     PicDownloadDelegate picDl = new PicDownloadDelegate(base.DownloadPic);
     picDl.BeginInvoke(url, action, new AsyncCallback(DownloadPicCallBack), null);
 }