我需要一个每秒检查数据库中的值是否为真的过程,这由 Windows 服务设置为真。
当值为 true 时更新图像。但我需要在值为 false 时,用户可以自由地在页面中进行其他活动。
我一直在寻找多线程通信,但我真的没有找到满足我特定需求的东西。
谢谢你的帮助
在这里,我添加了我拥有的代码:
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
}
}
}