dosend.cpp

来自「PDA通讯网关服务器源码程序」· C++ 代码 · 共 90 行

CPP
90
字号
// DoSend.cpp : implementation file
//

#include "stdafx.h"
#include "GateAgent.h"
#include "DoSend.h"
#include "PubConst.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDoSend
extern int g_nMax;
extern bool g_bRun;
extern CRITICAL_SECTION           g_SmsCritical;
extern  bool g_bExistMustBackSms;

IMPLEMENT_DYNCREATE(CDoSend, CWinThread)

CDoSend::CDoSend()
{
}

CDoSend::~CDoSend()
{
	if (g_nMax>0)
	{
		g_nMax=g_nMax-1;
		CString strTmp;
		strTmp.Format("发送线程退出,目前线程数目%d",g_nMax);
		m_pDlg->OnInsertMess(strTmp.GetBuffer(0),true,false);
	}
}

BOOL CDoSend::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int CDoSend::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CDoSend, CWinThread)
	//{{AFX_MSG_MAP(CDoSend)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDoSend message handlers

int CDoSend::Run() 
{
	int i=0;
	while(g_bRun)
	{
		//定时发送数据出去,消息队列当中如果没有数据,则从数据库当中轮询查找记录发送
		if (g_bExistMustBackSms)
		{
			EnterCriticalSection(&g_SmsCritical);		
			int iRet=m_pDlg->OnPreSend(m_iSendNum,0,"");//定时间发送消息
			LeaveCriticalSection(&g_SmsCritical);
				
			if (iRet==NO_SEND)//如果没有要发送的记录,
			{
				g_bExistMustBackSms=false;
//				m_pDlg->OnInsertMess("暂时没有记录要发送",true,false);
			}

		}
		Sleep(m_iSendTime);
		//保证定期发送下数据
		i++;
		if (i%99==0)
		{
			g_bExistMustBackSms=true;
			i=0;
		}
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?