amir100 Posted April 26, 2007 Posted April 26, 2007 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? Quote Amir Syafrudin
Administrators PlausiblyDamp Posted April 26, 2007 Administrators Posted April 26, 2007 In the line 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
amir100 Posted April 27, 2007 Author Posted April 27, 2007 In the line 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 Quote Amir Syafrudin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.