LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
MaximumThreadCount Property
See Also 
Leadtools Namespace > RasterDefaults Class : MaximumThreadCount Property



Gets or sets the maximum number of threads used during processing. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Shared Property MaximumThreadCount As Integer
Visual Basic (Usage)Copy Code
Dim value As Integer
 
RasterDefaults.MaximumThreadCount = value
 
value = RasterDefaults.MaximumThreadCount
C# 
public static int MaximumThreadCount {get; set;}
C++/CLI 
public:
static property int MaximumThreadCount {
   int get();
   void set (    int value);
}

Property Value

An System.Int32 value that represents the maximum number of threads used during processing. Must be a value greater than or equals to 0. Default value is the number of CPUs/Cores in the current machine (System.Environment.ProcessorCount).

Example

Visual BasicCopy Code
Private Sub RasterDefaultsMaximumThreadCountExample()
      Using codecs As New RasterCodecs
         'This is a speed test using multithreading JPEG2000 load, to conduct this test correctly the machine has to have multiple CPUs/Cores.
         Dim image As RasterImage

         'This is just load the binaries.
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"))

         'Load with MaximumThreadCount equal to the number of CPUs/Cores first.
         RasterDefaults.MaximumThreadCount = 0
         Dim time As DateTime = DateTime.Now
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"))
         Console.WriteLine(" JPEG2000 load time {0} / thread {1}", DateTime.Now - time, RasterDefaults.MaximumThreadCount)

         'Load with MaximumThreadCount equal one.
         RasterDefaults.MaximumThreadCount = 1
         time = DateTime.Now
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"))
         Console.WriteLine(" JPEG2000 load time {0} / thread {1}", DateTime.Now - time, RasterDefaults.MaximumThreadCount)
         image.Dispose()
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
private void RasterDefaultsMaximumThreadCountExample()
   {
      using (RasterCodecs codecs = new RasterCodecs())
      {
         //This is a speed test using multithreading JPEG2000 load, to conduct this test correctly the machine has to have multiple CPUs/Cores.
         RasterImage image;
         //This is just load the binaries.
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"));

         // Load with MaximumThreadCount equal to the number of CPUs/Cores first.
         RasterDefaults.MaximumThreadCount = 0;
         DateTime time = DateTime.Now;
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"Image1.j2k"));
         Console.WriteLine(" JPEG2000 load time {0} / thread {1}", DateTime.Now - time, RasterDefaults.MaximumThreadCount);

         // Load with MaximumThreadCount equal one.
         RasterDefaults.MaximumThreadCount = 1;
         time = DateTime.Now;
         image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"));
         Console.WriteLine(" JPEG2000 load time {0} / thread {1}", DateTime.Now - time, RasterDefaults.MaximumThreadCount);
         image.Dispose();
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

Note: this property is currently supported by LEADTOOLS for Silverlight only.

Using two threads with a dual core machine or two CPUs will increase the processing speed significantly if the processing supports parallel processing. Currently only the LEADTOOLS JPEG2000 Encoder and Decoder are using this property. More LEADTOOLS encoders/decoders may use this property in the future.

Possible values are:

Value Description
0

The toolkit will pick the proper number of running threads based on the number of CPUs/Cores of the current machines. Note: the toolkit will calculate this value internally and set it. Getting the value of this property will never return 0.

1 Use one thread only. In this case, the toolkit will not create extra threads for the processing, instead, all operations will be performed in the main thread.
2 Use two threads. The toolkit will create a maximum of two threads for processing if needed.
N Use N threads. The toolkit will create a maximum of N threads for processing if needed.

Values less than zero will be rejected. Large values, more than the number of CPU/Cores, will not increase performance and might cause resource usage overload which could lead to processing failure.

The MaximumThreadCount property is a global resource used by all LEADTOOLS and is not thread-safe. Make sure to use property thread synchronization if required.

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also