AsyncWebClient Property (original) (raw)
Summary
Gets the WebClient object used for asynchronous operations.
Syntax
public WebClient AsyncWebClient { get; }
public:
property WebClient^ AsyncWebClient {
WebClient^ get();
}
Property Value
A WebClient object that will be used for asynchronous operations.
Example
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;
public void UseAsyncExample()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
Uri uri = new Uri(srcFileName);
RasterCodecs codecs = new RasterCodecs();
// The RasterCodecs.AsyncWebClient is null first
Debug.Assert(codecs.AsyncWebClient == null);
// Force the RasterCodecs object to create it
codecs.UseAsync();
// Change the Cache policy
codecs.AsyncWebClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.CacheOnly);
// Now Load the file asynchronously
codecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(useAsyncExample_LoadAsyncCompleted);
RasterImage image = codecs.LoadAsync(uri, null);
}
private void useAsyncExample_LoadAsyncCompleted(object sender, CodecsLoadAsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
Debug.WriteLine("User canceled");
}
else if (e.Error != null)
{
Debug.WriteLine("Error: " + e.Error.Message);
}
else
{
// Get the image
RasterImage image = e.Image;
Debug.WriteLine("Image loaded asynchronously: Size = {0} by {1}", image.Width, image.Height);
image.Dispose();
}
// Unsubscribe to the event and dispose the RasterCodecs object
RasterCodecs codecs = sender as RasterCodecs;
codecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(useAsyncExample_LoadAsyncCompleted);
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Leadtools.Codecs Assembly
CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method
CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method
CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method
CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method