所以,我有一箇中繼器,顯示遠程服務器上的自定義函數列表。中繼器顯示如下。使用ServerController和更新面板更新不起作用
serverName serviceName serviceStatus Button1 Button2
----------------------------------------------------------
Carolina StatsTracker Running update stop
...
..
.
的serviceStatus被振打在一個更新面板中繼
<asp:UpdatePanel ID="statusUpdate" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<td><asp:Label ID="RowStatus" Width="100px" Text="Status..." runat="server" /></td>
</ContentTemplate>
</asp:UpdatePanel>
內部和在後面的代碼我經由servercontroller和試圖更新serviceStatus實時或至少爲向服務器發送命令儘可能接近實時。像這樣
if (svc.Status != ServiceControllerStatus.Stopped)
{
svc.Stop();
StatusLabel.Text = "Stopping";
statusUPdatePanel.Update();
while (svc.Status != ServiceControllerStatus.Stopped)
{
System.Threading.Thread.Sleep(1000);
svc.Refresh();
}
StatusLabel.Text = svc.Status.ToString();
statusUPdatePanel.Update();
}
System.Threading.Thread.Sleep(1000);
if (svc.Status != ServiceControllerStatus.Running)
{
svc.Start();
StatusLabel.Text = "Starting";
statusUPdatePanel.Update();
while (svc.Status != ServiceControllerStatus.Running)
{
System.Threading.Thread.Sleep(1000);
svc.Refresh();
}
StatusLabel.Text = svc.Status.ToString();
statusUPdatePanel.Update();
}
此問題是狀態不會實時更新。它只會更新爲正在運行或錯誤的最終值。但從不顯示停止,開始或停止。還在按鈕上單擊我禁用按鈕時,serverController正在運行,一個小型用戶打樣步驟,並且似乎不會導致按鈕被禁用。我讀過大量的updatepanel問題帖子,認爲這可能是一個有約束力的問題,但我不確定,因爲我已經厭倦了許多建議的解決方案,無濟於事。
在此先感謝您的幫助。
感謝您的回覆,這似乎相當有用。特別是'ServiceController.WaitForStatus(ServiceControllerStatus.Running,新的TimeSpan(0,0,5));'但我想更多地讓更新面板更新多次文本更改事件,但不確定。也許可以通過與代碼後面的repeater item命令事件相互依賴的另一種方法。不過,我相信你的回答是有效的,但是會等到我能實施它,看看它是否適用於我的情況,作爲答案。正如我所指出的那樣,非常感謝 – user1250570
,在一個請求中有**無法從_server更新面板多次**。你將不得不提出兩個請求(_partial,完整 - 通過按鈕或ajax ..._) - 很高興我可以幫助 –
所以我有一個問題適應這個主頁面,我不是很熟悉jQuery的。我假設我需要調整標識符? – user1250570