我需要一個進程,每秒檢查一次來自數據庫的值是否爲true,通過windows服務將其設置爲true。每秒鐘檢查數據庫值,同時允許用戶做其他事情
當值爲true時更新圖像。 但我需要,而價值是假的,用戶可以自由地在頁面上做其他活動。
我一直在尋找多線程通信,但我真的沒有找到我需要的東西。
感謝您的幫助
在這裏,我將我的代碼有:
private static class QuickUpdateCompletedCheck
{
#region BEGIN Declares
private static ProcessStatus quickUpdateCompletedStatus;
private static Thread quickUpdateThread;
private static ISynchronizeInvoke quickUpdateCompletedSynch;
private static bool updateCompleted;
private static QuickUpdateInfo quickUpdateInfo = null;
public delegate void UpdateCompletedStatusCheck(string Message, int status);
#endregion END Declares
#region BEGIN Initialization
public QuickUpdateCompletedCheck(ISynchronizeInvoke syn, ProcessStatus notify, Guid userIdLoc, int activityIdLoc, int fileIdLoc, int spreadIdLoc)
{
quickUpdateCompletedSynch = syn;
quickUpdateCompletedStatus = notify;
quickUpdateInfo = new QuickUpdateInfo(activityIdLoc, fileIdLoc, spreadIdLoc, userIdLoc);
}
#endregion END Initialization
#region BEGIN Methods
public void StartProcess()
{
quickUpdateThread = new System.Threading.Thread(new ParameterizedThreadStart(UpdateStatus));
//set the thread to run in the background
quickUpdateThread.IsBackground = true;
//name our thread (optional)
quickUpdateThread.Name = "Add List Items Thread";
//start our thread
quickUpdateThread.Start();
}
private static void UpdateStatus(object data)
{
QuickUpdateInfo quickUpdateInfo = (QuickUpdateInfo)data;
object[] dataInfo = new object[4];
dataInfo[0] = quickUpdateInfo.ActivityId;
dataInfo[1] = quickUpdateInfo.FileId;
dataInfo[2] = quickUpdateInfo.SpreadId;
dataInfo[3] = quickUpdateInfo.UserId;
quickUpdateCompletedSynch.Invoke(QuickUpdateCompletedataInfo); //Here I have an error need a delegate method in first parameter. i suppose is the QuickUpdateComplete method at the end of this description
}
#endregion END Methods
}
public class QuickUpdateInfo
{
private int activityId;
private int fileId;
private int spreadId;
private Guid userId;
public int ActivityId
{
get { return activityId; }
}
public int FileId
{
get { return fileId; }
}
public int SpreadId
{
get { return spreadId; }
}
public Guid UserId
{
get { return userId; }
}
public QuickUpdateInfo(int activityId, int fileId, int spreadId, Guid userId)
{
this.activityId = activityId;
this.fileId = fileId;
this.spreadId = spreadId;
this.userId = userId;
}
}
這種方法是在頁面的圖像最被更新
public partial class SpreadCorrection : BasePage
{
protected void UpdatePostBack_OnClick(object sender, EventArgs e)
{
//how to start Thread here
}
private static void QuickUpdateComplete(int activityId, int fileId, int spreadId)
{
if (value from database is true)
{
UpdateImage();
//how to stop Thread here
}
}
}
*爲什麼*不能爲你多線程工作? –
你真的認爲你是第一個遇到這種問題的人,在互聯網上什麼都沒有?我將這個問題解釋爲:*我懶得閱讀所有這些東西,發佈一個工作解決方案* – I4V
好的多線程我的東西是answear,但我已經嘗試了幾個例子。無論如何感謝您的評論。 – crendon