我使用jquery和一个输出页面完成了这项工作,该页面将返回已清除进程的PID。它是硬编码从4个工作进程中删除的,并且尝试次数不超过10次,通常它是在4次连续尝试中获得的。
function RemoveFromCache(buttonname, cachename) {
var allprocesses = new Array();
var trynumber = 1;
RemoveOneItem(buttonname, cachename, allprocesses, trynumber);
}
function RemoveOneItem(buttonname, cachename, allprocesses, trynumber) {
var jqxhr = $.get('/admin/cacheitems.aspx', { CacheName: cachename },
function(data) {
if (allprocesses.length == 0) {
$("#" + buttonname).attr('value', data);
allprocesses.push(data);
} else if (allprocesses.length < 4) {
var i=0;
var found = false;
for (i = 0; i < allprocesses.length; i++) {
if (allprocesses[i] == data) {
found = true;
}
}
if (found == false) {
$("#" + buttonname).attr('value', $("#" + buttonname).attr('value') + ',' + data);
allprocesses.push(data);
}
}
if (trynumber < 10) {
if (allprocesses.length < 4) {
trynumber++;
//this slows it down so it can hit a different process
$("#" + buttonname).delay(1000);
RemoveOneItem(buttonname, cachename, allprocesses, trynumber);
} else {
$("#" + buttonname).attr('value', $("#" + buttonname).attr('value') + ',REMOVED');
}
} else {
$("#" + buttonname).attr('value', $("#" + buttonname).attr('value') + ',INCOMPLETE');
}
}
);
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
If Not IsNothing(Request.QueryString("CacheName")) Then
RemoveFromCache(Request.QueryString("CacheName"))
Else
Load_Data()
End If
End If
End Sub
Sub RemoveFromCache(ByVal CacheName As String)
HttpContext.Current.Cache.Remove(CacheName)
Dim encBytes As New System.Text.UTF8Encoding()
Dim bArray() As Byte = encBytes.GetBytes(CStr(System.Diagnostics.Process.GetCurrentProcess().Id))
Response.Clear()
Response.ContentType = "text/plain"
Response.AddHeader("Content-Length", SharedCode.GetField(bArray.Length))
Response.BinaryWrite(bArray)
Response.End()
End Sub
Protected Sub dgCacheItems_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgCacheItems.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim btn As Button = CType(e.Item.FindControl("btnRemove"), Button)
btn.Attributes("title") = "Remove " & CStr(drv("ItemName"))
'btn.CommandName = "Remove"
'btn.CommandArgument = CStr(drv("ItemName"))
btn.OnClientClick = "RemoveFromCache('" & btn.ClientID & "','" & CStr(drv("ItemName")) & "'); return false;"
End If
End Sub