我在Silverlight中實現WCF。Silverlight WCF - 無效的交叉線程繁忙指標異常
在Silverlight中調用WCF服務時,我想給用戶顯示'BusyIndicator'。
我偶然在link上實現了busyindicator。
這是用C#編寫的。我正在vb.net開發項目。
無法正確地將其轉換爲vb.net
busyIndicator.IsBusy = true;
//busyIndicator.BusyContent = "Fetching Data...";
ThreadPool.QueueUserWorkItem((state) =>
{
Thread.Sleep(3 * 1000);
Dispatcher.BeginInvoke(() => busyIndicator.IsBusy = false);
}
雖然在我的要求執行上面的代碼
在VB.Net的代碼如下:
busyIndicator.IsBusy = True
ThreadPool.QueueUserWorkItem(Sub(state)
Dim s As New services.ServiceClient
AddHandler s.confirmticketCompleted, AddressOf mcompleted
s.confirmticketAsync()
Dispatcher.BeginInvoke(Sub()
busyIndicator.IsBusy = False
End Sub)
End Sub)
Sub mcompleted(sender As System.Object, e As services.confirmticketCompletedEventArgs)
MessageBox.Show(e.Result)
End Sub
服務在哪裏.serviceclient是WCF代理變量s
已完成的事件處理程序需要用來獲取返回值。
執行代碼後,我得到``無效的跨線程訪問。'在 MessageBox.Show(e.Result)異常
我的問題是類似link available at StackOverflow
但我不明白Ken2k先生說。
請指導並幫助我解決問題。