Under rare conditions, the creation of a new ServerTextControl TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications.
instance can fail and the Dispose method returns false. In these cases, the instance itself exists, but cannot be used. For example, a typical error when loading a document with an instance that could not be created is:

The TXTextControl object must have been completely loaded to use this method.

In these cases, the Create TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
Create Method
Initializes the resources of a newly instantiated object.
method returned false and the instance should not be used.

Restart IIS?

Some users report that only an IIS restart helps to resolve this situation. Technically, a restart helps as the process is re-created and existing USER handles are being released. But in fact, only USER handles must be released and there is no need to restart IIS or the worker process.

Possible Reasons

The most typical reason that a ServerTextControl cannot be created is that it is not possible to create a new Window handle. In Windows, there is a limit of 10,000 USER handles and 10,000 GDI objects handles. If this number is exceeded, it is not possible to create a new ServerTextControl instance. In typical applications, it is very most unlikely that this number of handles is created.

Sometimes, we see reports from users that this issue is caused after several days and very inconsistent or sporadic. Most likely, in these cases, the ServerTextControl instances are not properly disposed. It is very important to dispose ServerTextControl objects explicitly. We recommend to use them in a using statement:

Loading...

A better way would be to check whether the Create method has been called successfully:

Loading...

ServerTextControl Factory Class

To monitor the created instances, we implemented a factory class that returns valid instances of ServerTextControl. This diagnostics class can be also used to check the number of active instances, USER handles and GDI handles. Additionally, it can be used to dispose all active instances.

Loading...

Using the Class

This class uses the singleton pattern and can be created only once in an application:

Loading...

Once created, the CreateServerTextControl method creates and returns a new instance:

Loading...

When using this factory class, it is not required to create the ServerTextControl before using it. This is handled in the factory itself.

The ServerTextControlFactory creates and returns a new instance of ServerTextControl and stores it in a list. In case the instance cannot be created, the class returns null. When the instance is disposed, it is removed from that list again automatically. The method ServerTextControlFactory.Count returns the number of active ServerTextControl instances.

When executing the following code, the created ServerTextControl instance is disposed explicitly in the using statement. Therefore, the counter should be 0 after a successful execution.

Loading...
Number of instances: 1
Number of instances: 0

In case the ServerTextControl is not disposed, the active instance stays in the list until disposed:

Loading...
Number of instances: 0
Number of instances: 1

Debugging

When using this factory class in your application, you can always monitor the number of instances to find leaks. In case you would like to dispose all instances - for debugging purposes - the factory class provides the DisposeAll method that loops through all stored instances in order to dispose them:

Loading...
Number of instances: 0
Number of instances: 1
Number of instances: 2
Number of instances: 3
Number of instances: 4
Number of instances: 5
Disposed instances: 5

Handle Counter

Additionally, the factory class provides properties to return the number of USER and GDI handles in the current process:

Loading...
USER handles: 30
GDI handles: 26

Further Help

If you need assistance of further help debugging these kind of problems, talk to our engineers - we are here to help!