APM

来源:互联网 发布:网络ftp 编辑:程序博客网 时间:2024/04/16 19:53

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace APM
{
public partial class Form1 : Form
{
string filename;
#region 第一步,加载内存
private void ReadIntoMemory()
{
if(String.IsNullOrEmpty(filename))
{
MessageBox.Show(“文件名不能为空”);
return;
}
string result;
long mainCount = 0;
using (StreamReader sr = new StreamReader(filename,Encoding.Default))
{
while((result = sr.ReadLine())!=null)
{
mainCount++;

            }        }    }    #endregion    #region 第二步,处理数据    private void ProcessRecords()    {    }    #endregion    #region 典型的APM处理    /*     * 长时间处理函数绑定在一个action委托上,然后函数回调     */    private void BeginReadIntoMemory()    {        Action action = new Action(ReadIntoMemory);        action.BeginInvoke(new AsyncCallback(EndReadIntoMemory), action);    }    private void EndReadIntoMemory(IAsyncResult ar)    {        Action action = (Action)ar.AsyncState;        action.EndInvoke(ar);    }    private void BeginProcessRecords()    {        Action action = new Action(ProcessRecords);        action.BeginInvoke(new AsyncCallback(EndProcessRecords), action);    }    private void EndProcessRecords(IAsyncResult ar)    {        Action action = (Action)ar.AsyncState;        action.EndInvoke(ar);    }    #endregion    public Form1()    {        InitializeComponent();    }}

}

0 0
原创粉丝点击