BackgroundWorker保存文件

        /// <summary>
        /// 异步保存文件
        /// </summary>
        /// <param name="logout"></param>
        /// <returns></returns>
        private bool SaveFileAsync(string fileName)
        {
            try
            {
                BackgroundWorker workAssign = new BackgroundWorker();
                workAssign.DoWork += SaveFileDoWork;
                workAssign.RunWorkerAsync(fileName);
                return true;
            }
            catch (System.Exception ex)
            {
                StaticMethod.WriteLog(ex);
                return false;
            }
        }

        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveFileDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var fileName = e.Argument.ToString();
                for (int i = 0; i < m_streams.Count; i++)
                {
                    Metafile image = new Metafile(m_streams[i]);
                    image.Save(fileName + "_" + i + ".png", ImageFormat.Png);
                }
            }
            catch (System.Exception ex)
            {
                StaticMethod.WriteLog(ex);
            }
        }

 

posted @ 2018-12-29 10:14  江境纣州  阅读(16)  评论(0)    收藏  举报