Q&A

  • Thread 종료시에 error 발생합니다.
Thread 선언부 :
  TSendToChildThread = class(TThread)
  private
  protected
    procedure SendToChild;
    procedure Execute; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;

Thread 구현부 :
constructor TSendToChildThread.Create;
begin
  Inherited Create(False);
  FreeOnTerminate := True;
end;

destructor TSendTOChildThread.Destroy;
begin
  Inherited Destroy;
end;

procedure TSendTOChildThread.Execute;
begin
  while Not Terminated do
  begin
    IF MainForm.DSendTOChild.Count > 0 Then
    begin
      try
        WaitForSingleObject(MainForm.hMutex, INFINITE);
        Synchronize(SendToChild);
      finally
        ReleaseMutex(MainForm.hMutex);
      end;
      sleep(500);
    end;
  end;
end;

procedure TSendToChildThread.SendToChild;
begin
// Child Form으로 Data 전송
end;

MainForm Destroy시 thread Free :
procedure TMainForm.FormDestroy(Sender: TObject);
begin
  if (SendToChildThread <> nil) and (not SendToChildThread.Terminated) then
  begin
    SendToChildThread.Terminate;
    SendToChildThread.WaitFor;
  end;
  SendToChildThread.Free;
end;

SendToChildThread.Free <---- 이부분에서 external exception error C0000008 이 발생합니다.
이 부분을 없애면 너무많은 error로 인해 중단되었다고 나오구요...

도와주세요. 부탁입니당.
6  COMMENTS