Indy FTP 警告:Only one TIdAntiFreeze can be active in an application

> Should I use a AntiFreeze component on every form I have a TIdTCPClient 
> component?  Or is one enough to handle the whole Application? 

 

 

One is enough. According to the Indy help file, 

-------- 
Only one TIdAntiFreeze can be active in an application. If another 
instance already exists, an exception is raised. 
-------- 

Note that if you have multiple TIdTCPClient objects connected at the 
same time, and you call ReadXXX twice or more often (e. g. on a button 
click event) in the main thread context, then the last called ReadXXX 
will return first, blocking the other ReadXXX requests even if they 
could return data. This is because of the nature of the AntiFreeze 
mechanism. 

To avoid this effect, use a dedicated reader thread for each connection 
instead of AntiFreeze. There is a TIdTCPClient descendant with its own 
reader thread, firing an event when data arrive, at 
http://come.to/delphi-bits . 

-Michael 

 

 

 

 

TIdAntiFreeze
Prevents an application UI from freezing.
TIdAntiFreeze = class(TIdAntiFreezeBase)
Unit
Description
Indy works on the blocking model. That is when calls are made to Indy the do not return until they are complete. If calls are made in the main thread this will cause the Application User Interface to "freeze" during Indy calls. TIdAntiFreeze counter acts this effect. TIdAntiFreeze allows Indy subsystem to make process Application message calls so that Windows messages continue to be executed while Indy blocking socket calls are in effect.

Only one TIdAntiFreeze can be active in an application. If another instance already exists, an exception is raised. TIdAntiFreezeBase uses the global variable GAntiFreeze, declared in the TIdAntiFreezeBase unit, to determine if another instance has already been created.

Note: GAntiFreeze is not assigned if an instance is added in the form designer (during design time).

Note: The TIdAntiFreeze.pas unit must NOT appear in the uses clause of any Indy or descendant unit. This unit is linked in an application when the component is placed on a Form. This is done to preserve isolation from the Forms.pas and QForms.pas units.


TIdAntiFreeze.Process
Implements TIdAntifreeze functionality.
procedure Process; override;
Description
Process is the overridden implementation of the abstract virtual  TIdAntiFreezeBase.Process method. Process inspects the ApplicationHasPriority property to determine if Application.ProcessMessages is called. If False, the pending Windows message is dispatched to Application.HandleMessage.

Note: Due to the differences in message dispatching, Process does not use or inspect ApplicationHasPriority on the Linux Platform; Process simply calls Application.ProcessMessages.

Note: The TIdAntiFreeze.pas unit must NOT appear in the uses clause of any Indy or descendant unit. This unit is linked in an application when the component is placed on a Form. This is done to preserve isolation from the FORMS.PAS and QForms.pas units.

 

 

 

转载于:https://www.cnblogs.com/kayvanguo/p/5693834.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用TIdAntiFreeze对抗“冻结”   Indy使用一个特殊的组件TIdAntiFreeze来透明地解决客户程序用户界面“冻结”的问题。TIdAntiFreezeIndy内部定时中断对栈的调用,并在中断期间调用Application.ProcessMessages方法处理消息,而外部的Indy调用继续保存阻塞状态,就好像TIdAntiFreeze对象不存在一样。你只要在程序中的任意地方添加一个TIdAntiFreeze对象,就能在客户程序中利用到阻塞式Socket的所有优点而避开它的一些显著缺点。   Indy使用了线程技术   阻塞式Socekt通常都采用线程技术,Indy也是如此。从最底层开始,Indy的设计都是线程化的。因此用Indy创建服务器和客户程序跟在Unix下十分相似,并且Delphi的快速开发环境和Indy对WinSock的良好封装使得应用程序创建更加容易。   Indy服务器模型   一个典型的Unix服务器有一个或多个监听进程,它们不停地监听进入的客户连接请求。对于每一个需要服务的客户,都fork一个新进程来处理该客户的所有事务。这样一个进程只处理一个客户连接,编程就变得十分容易。   Indy服务器工作原理同Unix服务器十分类似,只是Windows不像Unix那样支持fork,而是支持线程,因此Indy服务器为每一个客户连接分配一个线程。   图1显示了Indy服务器的工作原理。Indy服务器组件创建一个同应用程序主线程分离的监听线程来监听客户连接请求,对于接受的每一个客户,都创建一个新的线程来为该客户提供服务,所有与这一客户相关的事务都由该线程来处理。   使用组件TIdThreadMgrPool,Indy还支持线程池。   线程与Indy客户程序   Indy客户端组件并未使用线程。但是在一些高级的客户程序中,程序员可以在自定义的线程中使用Indy客户端组件,以使用户界面更加友好。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值