Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending Email Asynchronously
Message
From
18/01/2013 14:26:02
 
 
To
18/01/2013 13:39:20
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01563134
Message ID:
01563301
Views:
38
>>>>>>>>Superb! Thanks once again Viv. What is interesting is that all the email is now being sent, but the code never hits the SendCompletedCallback.
>>>>>>>>
>>>>>>>>Oh, it also does not seem to be running asynchronously as I don't get control back in the UI for quite a while.
>>>>>>>>
>>>>>>>>One of these days I'll understand C# :(
>>>>>>>
>>>>>>>Viv,
>>>>>>>
>>>>>>>I commented out the wiatHandle.WaitOne(); and then my code stopped hanging. Do I need that line of code in there? Is it just in the wrong place?
>>>>>>
>>>>>>I think you need it - otherwise the whole PostAWBS method will exit before the async calls are complete. Are you sure all the emails were sent when it was removed ?
>>>>>>
>>>>>>P.S Ignore the update to my last post. As you found the SendCompletedCallback will fire whether it is static or not.
>>>>>
>>>>>You're right, just less than half were sent. So do I need to make my PostAWBs asynchronous too? How?
>>>>
>>>>If you're on .NET 4 then it's quite a bit more work than 4.5 which has the 'await' pattern :-{
>>>>
>>>>See this link : http://msdn.microsoft.com/en-us/library/2e08f6yc(v=vs.100).aspx
>>>>You'd need to use the last (most complicated :{ ) version : 'Execute a callback when an asynchronous call completes'.
>>>>
>>>>(or move to 4.5 :-} )
>>>
>>>Thanks, I'll check it out. 4.5 is not an option at the moment as Mere Mortals.NET doesn't support that version yet.
>>
>>Shouldn't be any reason why a 4.5 application should not reference 4.0 assemblies. But, of course, you would need both for deployment.
>>
>>Or, AFAIR, since MM includes source code you could recompile that for 4.5 .....
>
>when I asked about this before they said they only support 4.0, but I could be wrong.
>
>Here's what I've got so far (I hope I've chosen the correct one that you pointed me to):
>
>This is the code that calls my PostAWBs:
>
>
        private void btnPost_Click(object sender, RoutedEventArgs e)
>        {
>            PostAWBBusinessProcess PostAWB = new PostAWBBusinessProcess();
>
>            AsyncMethodCaller caller = new AsyncMethodCaller(PostAWB.PostAWBs);
>
>            IAsyncResult result = caller.BeginInvoke(3000,
>                new AsyncCallback(CallbackMethod));
>            
>            //PostAWB.PostAWBs();
>            
>
>            this.Close();
>        }
>
>I get two errors on the caller.BeginInvoke:
>
>1. Argument 1: cannot convert from 'int' to 'System.AsyncCallback'
>
>2. The best overloaded method match for 'SamaanSystems.IBC.WPF.AsyncMethodCaller.BeginInvoke(System.AsyncCallback, object)' has some invalid arguments
>
>What should I be passing as the first parameter there?
>
>My PostAWBs definition is:
>
>
        public int PostAWBs()
>        {...
>
>and my CallbackMethod:
>
>
        static void CallbackMethod(IAsyncResult ar)
>        {
>            // Retrieve the delegate.
>            AsyncResult result = (AsyncResult)ar;
>            AsyncMethodCaller caller = (AsyncMethodCaller)result.AsyncDelegate;
>
>            // Call EndInvoke to retrieve the results.
>            int returnValue = caller.EndInvoke(ar);
>
>        }
Your PostAWBs() should not probably take ManifestImportList as a parameter. The delegate sig would need to be adjusted accordingly and the first parameter to BeginInvoke() should be then be the ManifestImportList
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform