C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[6167] 쓰레드가 프로그램을 끝내버려요~ 도와주세요.
빌더소녀 [] 2180 읽음    2001-03-17 23:41
쓰레드를 사용하는 프로그램을 만들었어요.

메일 서버가 작동되는 상황에서 메일링리스트를 구현하는 데몬인데..

실행되고 일을 잘하더니 한 1분 내로 프로그램을 끝내버려요.

도움말을 보고 함 만들어 보았는데 어떻게 된 건지 모르겟네요~ 오빠들 많이 도와주세요.

다음은 쓰레드 구현부 소스입니다.

#include <vcl.h>
#pragma hdrstop

#include <DBTables.hpp>

#include "Work.h"
#pragma package(smart_init)


__fastcall TDowork::TDowork(bool CreateSuspended)
        : TThread(CreateSuspended)
{
   Priority = tpIdle;
}
//---------------------------------------------------------------------------
void __fastcall TDowork::Execute()
{

   while (!Terminated)
   {
      Synchronize(DistributeMail);
   }
}
//---------------------------------------------------------------------------

void __fastcall TDowork::DistributeMail()
{
   TQuery *query1, *query2;

   try
   {
      String Domain, List, Member, DomainPath, ListPath, MemberPath;

      query1 = new TQuery(Application);    <----- 의심가는 부분1
      query2 = new TQuery(Application);

      query1->DatabaseName = "Neant";
      query2->DatabaseName = "Neant";

      query1->Close();
      query1->SQL->Clear();
      query1->SQL->Add("SELECT DOMAINNAME, LIST FROM LIST");
      query1->Open();

      while (!query1->Eof)
      {
         Domain = query1->FieldByName("DOMAINNAME")->AsString;

         List = query1->FieldByName("LIST")->AsString;

         TSearchRec neant;

         DomainPath = RootPath + "\\" + Domain;

         ListPath   = DomainPath + "\\" + List + "\\" + "mailbox\\";

         int found = FindFirst(ListPath + "*.*", faAnyFile, neant);

         while (!found)
         {
            query2->Close();
            query2->SQL->Clear();
            query2->SQL->Add("SELECT MEMBER FROM MEMBER");
            query2->SQL->Add("WHERE DOMAINNAME = '" + Domain + "'");
            query2->SQL->Add("AND LIST = '" + List + "'");
            query2->Open();

            String SrcPath, DesPath;

            while (!query2->Eof)
            {
               Member = query2->FieldByName("MEMBER")->AsString;

               MemberPath = DomainPath + "\\" + Member + "\\mailbox\\";

               SrcPath = ListPath + neant.Name;
               DesPath = MemberPath + neant.Name;

               CopyFile(SrcPath.c_str(), DesPath.c_str(), false);

               query2->Next();
            }

            found = FindNext(neant);
            DeleteFile(SrcPath.c_str());
         }

         FindClose(neant);
         query1->Next();
      }
   }
   catch (...)
   {
      delete query1, query2;
      return;
   }

   delete query1, query2;

}

쓰레드 클래스 소스 (헤더)

class TDowork : public TThread
{
private:
protected:
        void __fastcall Execute();
public:
        String RootPath;

        void __fastcall DistributeMail();
       
        __fastcall TDowork(bool CreateSuspended);
};

쓰레드를 부리는 메인 소스

void __fastcall TListDemon::FormShow(TObject *Sender)
{
   Dowork = new TDowork(true);

   Dowork->RootPath = ExtractFileDir(UserdbPath);
   Dowork->Resume();
}

// nMail 메일링 리스트를 관리 설정하는 폼을 생성하는 루틴

void __fastcall TListDemon::Button1Click(TObject *Sender)
{
   Dowork->Terminate();

   try
   {
      if (AreUsers())
      {
         Configuration = new TConfiguration(this);
         Configuration->ShowModal();
      }
      else
      {
         ShowMessage("nMail Server에 등록된 사용자가 없어요! ^0^n");
      }
   }
   __finally
   {
      Configuration->Free();
   }

   Dowork->Resume();
}

void __fastcall TListDemon::FormClose(TObject *Sender, TCloseAction &Action)
{
   Dowork->Terminate();
   DeleteLocalAlias();
   Action = caFree;
}

얘는 프로젝트 소스파일이에요

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        HANDLE Mutex;

        try
        {
           // 프로그램을 한번만 실행시킴. 두번째 인스턴스 생성방지...

           const char ProgMutex[] = "NEANT";

           if ( ( Mutex = OpenMutex(MUTEX_ALL_ACCESS, false, ProgMutex) ) == NULL )
                  Mutex = CreateMutex(NULL, true, ProgMutex);
           else
              return 0;

           //nMail Server가 설치되어 있으면 리스트 데몬 활성화. 아니면 종료.

           if (IsnMailServer())
           {
                 Application->Initialize();
                 Application->CreateForm(__classid(TListDemon), &ListDemon);
                 Application->Run();
           }
           else
           {
                 String Alert;
                 Alert = "이 Machine에 nMail 서버가 설치되지 않았네요~ ^0^n";
                 MessageDlg(Alert.c_str(),mtConfirmation,TMsgDlgButtons() << mbOK, 0);
                 Application->Terminate();
           }
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }

        ReleaseMutex(Mutex);
        return 0;
}

참고로 운영체제는 윈도우 2000 어드밴스드 서버구여. 완벽하게 디버깅되어서 어떤 에러 어떤 경

고도 없어요 근데 왜 자동으로 프로그램이 끝나버릴까요 끝나기 전에도 일은 잘하구요. 매우 궁금

해요. 가르켜 주세요 *^0^*

                                                             - 나의 사랑 에보니 -



+ -

관련 글 리스트
6167 쓰레드가 프로그램을 끝내버려요~ 도와주세요. 빌더소녀 2180 2001/03/17
6188     자체 해결과 수정된소스입니다. 빌더소녀 2609 2001/03/19
6182     Re:쓰레드가 프로그램을 끝내버려요~ 도와주세요. - 답변이라기보다는 참고 및 질문 박세용 2485 2001/03/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.