14 10 2022

异步委托

private delegate void RunSyncDelegate();


private void RunSyncCallBack(IAsyncResult iAR)

{

        RunSyncDelegate runDoc = (RunSyncDelegate)iAR.AsyncState;

        runDoc.EndInvoke(iAR);

}


private void SyncDealByDay()

{

        //Do Something

}


//使用

RunSyncDelegate runDos = new RunSyncDelegate(SyncDealByDay);

AsyncCallback ac = new AsyncCallback(RunSyncCallBack);//异步呼叫

IAsyncResult iAResult = runDos.BeginInvoke(ac, runDos);


异步委托带参

private delegate void RunSyncDelegate(string projectGUID, string personGUID, string organizationGUID, DateTime attendanceTime, string deviceNo, string deviceName);


private void RunSyncCallBack(IAsyncResult iAR)

{

        RunSyncDelegate runDoc = (RunSyncDelegate)iAR.AsyncState;

        runDoc.EndInvoke(iAR);

}


private void SyncDealByDay(string projectGUID, string personGUID, string organizationGUID, DateTime attendanceTime, string deviceNo, string deviceName)

{

        //Do Something

}


//使用

RunSyncDelegate runDos = new RunSyncDelegate(SyncDealByDay);

AsyncCallback ac = new AsyncCallback(RunSyncCallBack);//异步呼叫

IAsyncResult iAResult = runDos.BeginInvoke(ProjectGUID, PersonGUID, OrganizationGUID, attendanceTime, deviceNo, deviceName, ac, runDos);

延伸阅读
  1. Mysql 随机获得表的几条记录
  2. Mysql开启远程连接
发表评论