Reputation: 2760
Is there a way of using Websync Publisher asynchronously? Currently I'm doing this
var publisher = new Publisher(url);
var result = publisher.Publish(publication);
if (!result.Successful)
//Log exception
The problem with this version is that when making the first Publish it takes somewhere around 2 seconds. I saw on some forums that in earlier versions of Websync they offered the possibility of using Publisher asynchronously see here, but for some reason that's not available in Websync 4.0
I've tried publishing asynchronously like this
var publisher = new Publisher(url);
Func<Publication> a = () => Publisher.Publish(publication);
a.BeginInvoke(result =>
{
var m = result.AsyncState as Func<Publication>;
if (m != null)
{
var asyncResult = m.EndInvoke(result);
if (!asyncResult.Successful)
// Log exception
}
}, a);
But this resulted in a "null reference" exception on
var asyncResult = m.EndInvoke(result);
which I couldn't really reproduce in development.
Any ideas on how to better approach this? Thank you
Upvotes: 1
Views: 163
Reputation: 4584
Try running your code on a thread-pool thread:
ThreadPool.QueueUserWorkItem((state) =>
{
var publisher = new Publisher(url);
var result = publisher.Publish(publication);
if (!result.Successful)
//Log exception
}, null);
It's short-lived, so you can use a thread from the CLR thread-pool.
Upvotes: 0