IAsyncResult == null

amir100

Centurion
Joined
Mar 14, 2004
Messages
190
Location
Indonesia
I'll get to the point.

Here's my code for calling conv.Convert asynchronously:
[csharp]
ToHTMLConverter conv = new ToHTMLConverter();
ASyncConvert aconv = new ASyncConvert(conv.Convert);
AsyncCallback aconvcallback = new AsyncCallback(this.HandleConverterCallback);
IAsyncResult result = aconv.BeginInvoke(fullpath, outfilename, out sErrMsg, true, aconvcallback, null);
[/csharp]

Here's my code defining HandleConverterCallback:
[csharp]
private void HandleConverterCallback(IAsyncResult result)
{
try
{
object sErrMsg;
ASyncConvert aconv = (ASyncConvert)result.AsyncState;
bool convertresult = aconv.EndInvoke(out sErrMsg, result);
}
catch (Exception ex)
{
// Problem occured when handling callback.
}
}
[/csharp]

The question is why is the result.AsyncState returns null? This has never happened before. I usually get the aconv object so that I can call the EndInvoke method.

Any clues?
 
In the line
C#:
IAsyncResult result = aconv.BeginInvoke(fullpath, outfilename, out sErrMsg, true, aconvcallback, null);
you are passing null as the last parameter - whatever you pass in here is what you get with the IAsyncResult.AsyncState property.
 
In the line
C#:
IAsyncResult result = aconv.BeginInvoke(fullpath, outfilename, out sErrMsg, true, aconvcallback, null);
you are passing null as the last parameter - whatever you pass in here is what you get with the IAsyncResult.AsyncState property.

I see.

I cross-checked with my original reference when creating the code. Not that I don't believe in you PlausiblyDamp. I just needed to know what should I pass in the last parameter.

I guess I miss that part. :D

Before I didn't use any AsyncCallback so I didn't notice that I needed to replace that last parameter.

Thank you for your reply. I find it very helpful. :D
 
Back
Top