有没有一种异步使用Websync发布服务器的方法?目前我正在做这个
var publisher = new Publisher(url);
var result = publisher.Publish(publication);
if (!result.Successful)
//Log exception这个版本的问题是,当第一个发布时,它需要大约2秒的时间。我在一些论坛上看到,在早期版本的Websync中,他们提供了异步使用Publisher 的可能性,但由于某些原因,在WebSync4.0中是不可用的
我尝试过像这样异步发布
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);但是,这导致了“空引用”异常
var asyncResult = m.EndInvoke(result);但在发育过程中我真的无法复制。
关于如何更好地处理这个问题,有什么想法吗?谢谢
发布于 2013-10-10 15:59:25
尝试在线程池线程上运行代码:
ThreadPool.QueueUserWorkItem((state) =>
{
var publisher = new Publisher(url);
var result = publisher.Publish(publication);
if (!result.Successful)
//Log exception
}, null);它是短暂的,所以您可以使用来自CLR线程池的线程。
https://stackoverflow.com/questions/17523645
复制相似问题