/// <summary> /// Runs the specified method on all of the connected servers. Runs the methods in parallel if there are multiple /// connected servers. Intelligently handles remoting exceptions and return values. /// </summary> /// <param name="method"></param> /// <param name="parameters"></param> /// <returns></returns> public ServerActionStatus runMethodOnConnectedServers(MethodInfo method, object[] parameters, int msTimeout, EventHandler <MessageEvent> messageLog) { Dictionary <IAsyncResult, runMethodOnServerDelegate> delegates = new Dictionary <IAsyncResult, runMethodOnServerDelegate>(); lock (servers) { foreach (ServerInfo server in servers) { if (isServerConnected(server)) { runMethodOnServerDelegate runDelegate = new runMethodOnServerDelegate(runMethodOnServer); IAsyncResult result = runDelegate.BeginInvoke(method, server, parameters, msTimeout, messageLog, null, null); delegates.Add(result, runDelegate); } } } ServerActionStatus ans = ServerActionStatus.Success; // now wait for all the threaded operations to complete foreach (IAsyncResult res in delegates.Keys) { runMethodOnServerDelegate del = delegates[res]; ServerActionStatus status = del.EndInvoke(res); if (status != ServerActionStatus.Success) { ans = status; } } return(ans); }
/// <summary> /// Runs the specified method on all of the connected servers. Runs the methods in parallel if there are multiple /// connected servers. Intelligently handles remoting exceptions and return values. /// </summary> /// <param name="method"></param> /// <param name="parameters"></param> /// <returns></returns> public ServerActionStatus runMethodOnConnectedServers(MethodInfo method, object[] parameters, int msTimeout, EventHandler<MessageEvent> messageLog) { Dictionary<IAsyncResult, runMethodOnServerDelegate> delegates = new Dictionary<IAsyncResult, runMethodOnServerDelegate>(); lock (servers) { foreach (ServerInfo server in servers) { if (isServerConnected(server)) { runMethodOnServerDelegate runDelegate = new runMethodOnServerDelegate(runMethodOnServer); IAsyncResult result = runDelegate.BeginInvoke(method, server, parameters, msTimeout, messageLog, null, null); delegates.Add(result, runDelegate); } } } ServerActionStatus ans = ServerActionStatus.Success; // now wait for all the threaded operations to complete foreach (IAsyncResult res in delegates.Keys) { runMethodOnServerDelegate del = delegates[res]; ServerActionStatus status = del.EndInvoke(res); if (status != ServerActionStatus.Success) { ans = status; } } return ans; }