2013-07-08 35 views
1

是否有異步使用Websync Publisher的方法? 目前我在做這個Websync 4.0 - 發佈者異步

var publisher = new Publisher(url); 
var result = publisher.Publish(publication); 
if (!result.Successful) 
    //Log exception 

的問題與此版本是使第一時發佈需要2秒左右的地方。 我看到,在早期版本的Websync他們提供使用出版商異步see here的可能性一些論壇,但由於某些原因,這不是提供Websync 4.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); 

,我不能在developm真正重現ENT。

關於如何更好地處理此問題的任何想法? 謝謝

回答

0

嘗試在一個線程池線程運行代碼:

ThreadPool.QueueUserWorkItem((state) => 
{ 
    var publisher = new Publisher(url); 
    var result = publisher.Publish(publication); 
    if (!result.Successful) 
     //Log exception 
}, null); 

這是短暫的,所以你可以從CLR線程池中使用的線程。