Multi-thread DAO Processing

Source: Internet
Author: User

 

 

There are many limitations in DAO multi-threaded processing, So I designed such a class to use DAO's forced calling through GUI threads. A gui message queue is used in the class. All calls to CMultiDAORecordset are forced to use AfxGetThread () to check the current thread. The GUI thread pointer is placed at the beginning of the InitInstance. If the introduced call request is not running in the GUI thread, CMultiDAORecordSet will send a WM_MULTIDAOMESSAGE message to AfxGetMainWnd () (IN Mainfrm. cpp ). When Mainfrm receives the message, the thread will run again. At this time, the message has been accepted, and the basic class CDaoRecordset will be called. Therefore, your class is inherited from CMultiDAORecordset, rather than CDaoRecordset, as shown below:

 

Class CMySet: public CMultiDaoRecordSet

 

In the corresponding CPP file, you should also change the following:

 

IMPLEMENT_DYNAMIC (CMySet, CMultiDaoRecordSet)

 

CMySet: CMySet (CDaoDatabase * pdb): CMultiDaoRecordSet (pdb)

To process the received WM_MULTIDAOMESSAGE, the following code should also be added to MainFrm:

 

In the MainFrm. h file, add:

# Ifdef MAINFRAME_CPP

UINT WM_MULTIDAOMESSAGE = RegisterWindowMessage ("WM_MULTIDAOMESSAGE ");

# Else

Extern UINT WM_MULTIDAOMESSAGE;

# Endif

 

Afx_msg LONG OnMultiDaoMessage (UINT uParam, LONG lParam );

In the MainFrm. cpp file, add:

# Define MAINFRAME_CPP

 

# Include "MutliDaoRecordset. h"

 

// Added to the message map

 

BEGIN_MESSAGE_MAP (CMainFrame, CMDIFrameWnd)

// {AFX_MSG_MAP (CMainFrame)

ON_REGISTERED_MESSAGE (WM_MULTIDAOMESSAGE, OnMultiDaoMessage)

END_MESSAGE_MAP ()

 

// This function added

LONG CMainFrame: OnMultiDaoMessage (UINT uParam, LONG lParam)

{

// Jtm

// Based on switch, perform operation...

CMultiDaoRecordSet * pSet = (CMultiDaoRecordSet *) lParam;

LONG lRet = 0;

 

CString cRet = "";

COleVariant cVar;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.